mirror of
https://github.com/AGWA/git-crypt.git
synced 2026-02-04 11:07:57 -08:00
Add touch_file() utility function
This commit is contained in:
@@ -31,7 +31,9 @@
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/wait.h>
|
||||
#include <sys/time.h>
|
||||
#include <errno.h>
|
||||
#include <utime.h>
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
#include <limits.h>
|
||||
@@ -274,6 +276,13 @@ bool successful_exit (int status)
|
||||
return status != -1 && WIFEXITED(status) && WEXITSTATUS(status) == 0;
|
||||
}
|
||||
|
||||
void touch_file (const std::string& filename)
|
||||
{
|
||||
if (utimes(filename.c_str(), NULL) == -1) {
|
||||
throw System_error("utimes", "", errno);
|
||||
}
|
||||
}
|
||||
|
||||
static void init_std_streams_platform ()
|
||||
{
|
||||
}
|
||||
|
||||
@@ -320,6 +320,25 @@ bool successful_exit (int status)
|
||||
return status == 0;
|
||||
}
|
||||
|
||||
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());
|
||||
}
|
||||
SYSTEMTIME system_time;
|
||||
GetSystemTime(&system_time);
|
||||
FILETIME file_time;
|
||||
SystemTimeToFileTime(&system_time, &file_time);
|
||||
|
||||
if (!SetFileTime(fh, NULL, NULL, &file_time)) {
|
||||
DWORD error = GetLastError();
|
||||
CloseHandle(fh);
|
||||
throw System_error("SetFileTime", filename, error);
|
||||
}
|
||||
CloseHandle(fh);
|
||||
}
|
||||
|
||||
static void init_std_streams_platform ()
|
||||
{
|
||||
_setmode(_fileno(stdin), _O_BINARY);
|
||||
|
||||
1
util.hpp
1
util.hpp
@@ -64,6 +64,7 @@ int exec_command (const std::vector<std::string>&);
|
||||
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&);
|
||||
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