mirror of
https://github.com/scylladb/scylladb.git
synced 2026-04-28 12:17:02 +00:00
touch_directory: EEXIST-ignoring make directory
There are many situations in which we would like to make sure a directory exists. We can do that by creating the directory we want, and just ignoring the relevant error. It is a lot of code though, and I believe it is an idiom common enough to exist on its own. Signed-off-by: Glauber Costa <glommer@cloudius-systems.com> Reviewed-by: Nadav Har'El <nyh@cloudius-systems.com>
This commit is contained in:
committed by
Avi Kivity
parent
534401c91f
commit
92803a2db3
@@ -1917,6 +1917,18 @@ future<> make_directory(sstring name) {
|
||||
return engine().make_directory(std::move(name));
|
||||
}
|
||||
|
||||
future<> touch_directory(sstring name) {
|
||||
return make_directory(name).then_wrapped([] (future<> f) {
|
||||
try {
|
||||
f.get();
|
||||
} catch (std::system_error& e) {
|
||||
if (e.code() != std::error_code(EEXIST, std::system_category())) {
|
||||
throw;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
future<> remove_file(sstring pathname) {
|
||||
return engine().remove_file(std::move(pathname));
|
||||
}
|
||||
|
||||
@@ -108,5 +108,6 @@ future<connected_socket> connect(socket_address sa);
|
||||
future<file> open_file_dma(sstring name, open_flags flags);
|
||||
future<file> open_directory(sstring name);
|
||||
future<> make_directory(sstring name);
|
||||
future<> touch_directory(sstring name);
|
||||
future<> remove_file(sstring pathname);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user