mirror of
https://github.com/AGWA/git-crypt.git
synced 2026-07-28 22:50:51 -07:00
Add umask and rename compatibility wrappers for Windows
umask() doesn't exist on Windows and is thus a no-op. rename() only works if the destination doesn't already exist, so we must unlink before renaming.
This commit is contained in:
committed by
Andrew Ayer
parent
dcea03f0d7
commit
df2b472cd9
+13
-3
@@ -69,14 +69,14 @@ void temp_fstream::open (std::ios_base::openmode mode)
|
||||
char* path = &path_buffer[0];
|
||||
std::strcpy(path, tmpdir);
|
||||
std::strcpy(path + tmpdir_len, "/git-crypt.XXXXXX");
|
||||
mode_t old_umask = umask(0077);
|
||||
mode_t old_umask = util_umask(0077);
|
||||
int fd = mkstemp(path);
|
||||
if (fd == -1) {
|
||||
int mkstemp_errno = errno;
|
||||
umask(old_umask);
|
||||
util_umask(old_umask);
|
||||
throw System_error("mkstemp", "", mkstemp_errno);
|
||||
}
|
||||
umask(old_umask);
|
||||
util_umask(old_umask);
|
||||
std::fstream::open(path, mode);
|
||||
if (!std::fstream::is_open()) {
|
||||
unlink(path);
|
||||
@@ -277,3 +277,13 @@ bool successful_exit (int status)
|
||||
static void init_std_streams_platform ()
|
||||
{
|
||||
}
|
||||
|
||||
mode_t util_umask (mode_t mode)
|
||||
{
|
||||
return umask(mode);
|
||||
}
|
||||
|
||||
int util_rename (const char* from, const char* to)
|
||||
{
|
||||
return rename(from, to);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user