Skip to content
This repository was archived by the owner on Dec 21, 2023. It is now read-only.

Commit b598e95

Browse files
author
Guihao Liang
authored
check on parent dir (#3105)
1 parent dc6523c commit b598e95

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

src/core/storage/fileio/fs_utils.cpp

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -290,26 +290,31 @@ EXPORT bool create_directory_or_throw(const std::string& path) {
290290
// this function throws if the directory still doesn't exist
291291
// at that location
292292
if (get_protocol(path) == "s3") {
293-
auto status = get_file_status(path);
293+
// only check on parent direcotory or prefix
294+
auto ppath = get_dirname(path);
295+
auto status = get_file_status(ppath);
296+
// no need to create subdirectory in s3 because there's none
294297
switch (status.first) {
295298
case file_status::MISSING:
296299
log_and_throw_io_failure(
297-
"Unable to create directory structure at " + sanitize_url(path) +
298-
". Ensure that you have write permission to this location, or try "
299-
"again with a different path. " +
300-
"error message: " + status.second);
301-
break;
300+
"Unable to find parent directory structure: " +
301+
sanitize_url(ppath) +
302+
". Ensure that you have created this s3 prefix. This behavior "
303+
"intends to avoid accidental creation S3 keys. or try "
304+
"again with a different path. Error message: " +
305+
status.second);
302306
case file_status::REGULAR_FILE:
303307
log_and_throw_io_failure(
304-
"Unable to create directory at " + sanitize_url(path) +
305-
". A non-directory file already exists there. Delete that file, or "
306-
"try again with a different path.");
308+
"Parent directory (prefix) " + sanitize_url(path) +
309+
" is a regular file. Use prefix as both file and directory is "
310+
"discouraged in order to prevent further ambiguity. Delete that "
311+
"file, or try again with a different path.");
307312
case file_status::DIRECTORY:
308313
// happy path, return below
309314
break;
310315
default:
311316
// not sure what error message to give; fall back to current I/O error
312-
log_and_throw_current_io_failure();
317+
log_and_throw_io_failure("Unknown error");
313318
}
314319
}
315320

0 commit comments

Comments
 (0)