# # patch "file_io.cc" # from [c328d2b14c072a853193222e836c5c4346a5f7c0] # to [23eddf8c6fbb41be5f69ad4d38418ab0cc165d3c] # # patch "file_io.hh" # from [8a8dcea0d9950cfcad01cb28c34690d09ee53d83] # to [62d02358ee6b7b6ba7c4dd93d4f7d387d4e1bf6b] # ======================================================================== --- file_io.cc c328d2b14c072a853193222e836c5c4346a5f7c0 +++ file_io.cc 23eddf8c6fbb41be5f69ad4d38418ab0cc165d3c @@ -206,15 +206,47 @@ } } +static void +do_shallow_deletion_with_sane_error_message(any_path const & p) +{ + fs::path fp = mkdir(p); + try + { + fs::remove(fp); + } + catch (fs::filesystem_error & err) + { + E(false, F("could not remove '%s'\n%s") + % err.path1().native_directory_string() + % strerror(err.native_error())); + } +} + void delete_file(any_path const & p) { require_path_is_file(p, F("file to delete '%s' does not exist") % p, F("file to delete, '%s', is not a file but a directory") % p); - fs::remove(mkdir(p)); + do_shallow_deletion_with_sane_error_message(p); } +void +delete_dir_shallow(any_path const & p) +{ + require_path_is_dir(p, + F("directory to delete '%s' does not exist") % p, + F("directory to delete, '%s', is not a directory but a file") % p); + do_shallow_deletion_with_sane_error_message(p); +} + +void +delete_file_or_dir_shallow(any_path const & p) +{ + N(path_exists(p), F("object to delete, '%s', does not exist") % p); + do_shallow_deletion_with_sane_error_message(p); +} + void delete_dir_recursive(any_path const & p) { ======================================================================== --- file_io.hh 8a8dcea0d9950cfcad01cb28c34690d09ee53d83 +++ file_io.hh 62d02358ee6b7b6ba7c4dd93d4f7d387d4e1bf6b @@ -52,6 +52,8 @@ void make_dir_for(any_path const & p); void delete_file(any_path const & path); +void delete_dir_shallow(any_path const & path); +void delete_file_or_dir_shallow(any_path const & path); void delete_dir_recursive(any_path const & path); void move_file(any_path const & old_path,