mirror of
https://github.com/AGWA/git-crypt.git
synced 2026-02-02 10:14:46 -08:00
Add multi-platform remove_file helper
And use it for deleting internal keys
This commit is contained in:
12
commands.cpp
12
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<std::string>& secret_keys, const std::string& keys_path)
|
||||
@@ -907,12 +903,12 @@ int lock (int argc, const char** argv)
|
||||
std::vector<std::string> dirents = get_directory_contents(get_internal_keys_path().c_str());
|
||||
|
||||
for (std::vector<std::string>::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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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 ()
|
||||
{
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
1
util.hpp
1
util.hpp
@@ -65,6 +65,7 @@ int exec_command (const std::vector<std::string>&, std::ostream& output);
|
||||
int exec_command_with_input (const std::vector<std::string>&, 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);
|
||||
|
||||
Reference in New Issue
Block a user