diff --git a/commands.cpp b/commands.cpp index d3c5069..4b593f6 100644 --- a/commands.cpp +++ b/commands.cpp @@ -372,13 +372,9 @@ static void load_key (Key_file& key_file, const char* key_name, const char* key_ } } -static void unlink_repo_key (const char* key_name) +static void unlink_internal_key (const char* key_name) { - std::string key_path(get_internal_key_path(key_name ? key_name : "default")); - - if ((unlink(key_path.c_str())) == -1 && errno != ENOENT) { - throw System_error("Unable to remove repo key", key_path, errno); - } + remove_file(get_internal_key_path(key_name ? key_name : "default")); } static bool decrypt_repo_key (Key_file& key_file, const char* key_name, uint32_t key_version, const std::vector& secret_keys, const std::string& keys_path) @@ -907,12 +903,12 @@ int lock (int argc, const char** argv) std::vector dirents = get_directory_contents(get_internal_keys_path().c_str()); for (std::vector::const_iterator dirent(dirents.begin()); dirent != dirents.end(); ++dirent) { - unlink_repo_key(dirent->c_str()); + unlink_internal_key(dirent->c_str()); unconfigure_git_filters(dirent->c_str()); } } else { // just handle the given key - unlink_repo_key(key_name); + unlink_internal_key(key_name); unconfigure_git_filters(key_name); } diff --git a/util-unix.cpp b/util-unix.cpp index 2bdf364..d31550b 100644 --- a/util-unix.cpp +++ b/util-unix.cpp @@ -285,6 +285,13 @@ void touch_file (const std::string& filename) } } +void remove_file (const std::string& filename) +{ + if (unlink(filename.c_str()) == -1) { + throw System_error("unlink", filename, errno); + } +} + static void init_std_streams_platform () { } diff --git a/util-win32.cpp b/util-win32.cpp index 4d442db..21576c7 100644 --- a/util-win32.cpp +++ b/util-win32.cpp @@ -340,6 +340,13 @@ void touch_file (const std::string& filename) CloseHandle(fh); } +void remove_file (const std::string& filename) +{ + if (!DeleteFileA(filename.c_str())) { + throw System_error("DeleteFileA", filename, GetLastError()); + } +} + static void init_std_streams_platform () { _setmode(_fileno(stdin), _O_BINARY); diff --git a/util.hpp b/util.hpp index aa04912..8b5bc33 100644 --- a/util.hpp +++ b/util.hpp @@ -65,6 +65,7 @@ int exec_command (const std::vector&, std::ostream& output); int exec_command_with_input (const std::vector&, const char* p, size_t len); bool successful_exit (int status); void touch_file (const std::string&); +void remove_file (const std::string&); std::string escape_shell_arg (const std::string&); uint32_t load_be32 (const unsigned char*); void store_be32 (unsigned char*, uint32_t);