mirror of
https://github.com/AGWA/git-crypt.git
synced 2025-12-05 20:40:05 -08:00
touch_file, remove_file: ignore non-existent files
This commit is contained in:
@@ -280,14 +280,14 @@ int exit_status (int wait_status)
|
||||
|
||||
void touch_file (const std::string& filename)
|
||||
{
|
||||
if (utimes(filename.c_str(), NULL) == -1) {
|
||||
if (utimes(filename.c_str(), NULL) == -1 && errno != ENOENT) {
|
||||
throw System_error("utimes", filename, errno);
|
||||
}
|
||||
}
|
||||
|
||||
void remove_file (const std::string& filename)
|
||||
{
|
||||
if (unlink(filename.c_str()) == -1) {
|
||||
if (unlink(filename.c_str()) == -1 && errno != ENOENT) {
|
||||
throw System_error("unlink", filename, errno);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -325,7 +325,12 @@ void touch_file (const std::string& filename)
|
||||
{
|
||||
HANDLE fh = CreateFileA(filename.c_str(), FILE_WRITE_ATTRIBUTES, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);
|
||||
if (fh == INVALID_HANDLE_VALUE) {
|
||||
throw System_error("CreateFileA", filename, GetLastError());
|
||||
DWORD error = GetLastError();
|
||||
if (error == ERROR_FILE_NOT_FOUND) {
|
||||
return;
|
||||
} else {
|
||||
throw System_error("CreateFileA", filename, error);
|
||||
}
|
||||
}
|
||||
SYSTEMTIME system_time;
|
||||
GetSystemTime(&system_time);
|
||||
@@ -343,7 +348,12 @@ void touch_file (const std::string& filename)
|
||||
void remove_file (const std::string& filename)
|
||||
{
|
||||
if (!DeleteFileA(filename.c_str())) {
|
||||
throw System_error("DeleteFileA", filename, GetLastError());
|
||||
DWORD error = GetLastError();
|
||||
if (error == ERROR_FILE_NOT_FOUND) {
|
||||
return;
|
||||
} else {
|
||||
throw System_error("DeleteFileA", filename, error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
4
util.hpp
4
util.hpp
@@ -65,8 +65,8 @@ 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);
|
||||
int exit_status (int wait_status); // returns -1 if process did not exit (but was signaled, etc.)
|
||||
inline bool successful_exit (int wait_status) { return exit_status(wait_status) == 0; }
|
||||
void touch_file (const std::string&);
|
||||
void remove_file (const std::string&);
|
||||
void touch_file (const std::string&); // ignores non-existent files
|
||||
void remove_file (const std::string&); // ignores non-existent files
|
||||
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