[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Monotone-devel] patch for umask on MinGW
From: |
Stephen Leake |
Subject: |
[Monotone-devel] patch for umask on MinGW |
Date: |
Sat, 28 Apr 2007 16:32:37 -0400 |
User-agent: |
Gnus/5.1006 (Gnus v5.10.6) Emacs/21.3 (windows-nt) |
Here is a possible fix for umask in key_store.cc on MinGW:
============================================================
--- key_store.cc
+++ key_store.cc
@@ -115,7 +115,7 @@ key_store::ensure_in_database(rsa_keypai
I(app.db.public_key_exists(ident));
return;
}
-
+
if (app.db.put_key(ident, i->second.pub))
L(FL("loaded public key '%s' into db") % ident);
}
@@ -212,11 +212,12 @@ key_store::write_key(rsa_keypair_id cons
system_path file;
get_key_file(ident, file);
- // set a restrictive umask, write the file and reset umask
- mode_t mask = umask(S_IRWXG|S_IRWXO);
- L(FL("writing key '%s' to file '%s' in dir '%s'") % ident % file % key_dir);
- write_data(file, dat, key_dir);
- umask(mask);
+ {
+ enable_restrictive_umask masker;
+
+ L(FL("writing key '%s' to file '%s' in dir '%s'") % ident % file %
key_dir);
+ write_data(file, dat, key_dir);
+ }
}
bool
============================================================
--- platform.hh
+++ platform.hh
@@ -1,7 +1,7 @@
#ifndef __PLATFORM_HH__
#define __PLATFORM_HH__
-// Copyright (C) 2002 Graydon Hoare <address@hidden>
+// Copyright (C) 2002, 2007 Graydon Hoare <address@hidden>
//
// This program is made available under the GNU GPL version 2.0 or
// greater. See the accompanying file COPYING for details.
@@ -82,7 +82,7 @@ public:
// this time in the future?" bit in the hashed information. This bit
// will change when we pass the future point, and trigger a re-check of
// the file's contents.
- //
+ //
// This is, of course, still not perfect. There is no way to make our stat
// atomic with the actual read of the file, so there's always a race
condition
// there. Additionally, this handling means that checkout will never
actually
@@ -122,6 +122,18 @@ void rename_clobberingly(std::string con
void rename_clobberingly(std::string const & from, std::string const & to);
+// key_store::write_key wants to set a more restrictive umask; that is not
+// supported by MinGW
+struct enable_restrictive_umask
+{
+ mode_t mask;
+
+ enable_restrictive_umask();
+ ~enable_restrictive_umask();
+};
+
+// end file system stuff
+
// strerror wrapper for OS-specific errors (e.g. use FormatMessage on Win32)
std::string os_strerror(os_err_t errnum);
============================================================
--- unix/fs.cc
+++ unix/fs.cc
@@ -1,4 +1,4 @@
-// copyright (C) 2005 nathaniel smith <address@hidden>
+// copyright (C) 2005, 2007 nathaniel smith <address@hidden>
// all rights reserved.
// licensed to the public under the terms of the GNU GPL (>= 2)
// see the file COPYING for details
@@ -125,6 +125,16 @@ rename_clobberingly(std::string const &
F("renaming '%s' to '%s' failed: %s") % from % to % os_strerror(errno));
}
+enable_restrictive_umask::enable_restrictive_umask()
+{
+ mask = umask(S_IRWXG|S_IRWXO);
+} // enable_restrictive_umask::enable_restrictive_umask
+
+enable_restrictive_umask::~enable_restrictive_umask()
+{
+ umask(mask);
+} // enable_restrictive_umask::~enable_restrictive_umask
+
// Local Variables:
// mode: C++
// fill-column: 76
============================================================
--- win32/fs.cc
+++ win32/fs.cc
@@ -1,4 +1,4 @@
-// copyright (C) 2005 nathaniel smith <address@hidden>
+// copyright (C) 2005, 2007 nathaniel smith <address@hidden>
// all rights reserved.
// licensed to the public under the terms of the GNU GPL (>= 2)
// see the file COPYING for details
@@ -150,33 +150,33 @@ rename_clobberingly_impl(const char * fr
{
HMODULE hModule = LoadLibrary("kernel32");
if (hModule)
- fnMoveFileEx = reinterpret_cast<MoveFileExFun>
- (GetProcAddress(hModule, "MoveFileExA"));
+ fnMoveFileEx = reinterpret_cast<MoveFileExFun>
+ (GetProcAddress(hModule, "MoveFileExA"));
if (fnMoveFileEx)
- {
- L(FL("using MoveFileEx for renames"));
- MoveFileExAvailable = true;
- }
+ {
+ L(FL("using MoveFileEx for renames"));
+ MoveFileExAvailable = true;
+ }
else
- L(FL("using DeleteFile/MoveFile fallback for renames"));
+ L(FL("using DeleteFile/MoveFile fallback for renames"));
}
if (MoveFileExAvailable)
{
if (fnMoveFileEx(from, to, MOVEFILE_REPLACE_EXISTING))
- return true;
+ return true;
else if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
- {
- MoveFileExAvailable = false;
- L(FL("MoveFileEx failed with CALL_NOT_IMPLEMENTED, using fallback"));
- }
+ {
+ MoveFileExAvailable = false;
+ L(FL("MoveFileEx failed with CALL_NOT_IMPLEMENTED, using fallback"));
+ }
}
else
{
// This is not even remotely atomic, but what can you do?
DeleteFile(to);
if (MoveFile(from, to))
- return true;
+ return true;
}
return false;
}
@@ -206,6 +206,18 @@ rename_clobberingly(std::string const &
% os_strerror(lastError) % lastError);
}
+enable_restrictive_umask::enable_restrictive_umask()
+{
+ // umask is not provided by MinGW. We assume MinGW boxes have single
+ // users, so this doesn't matter.
+
+} // enable_restrictive_umask::enable_restrictive_umask
+
+enable_restrictive_umask::~enable_restrictive_umask()
+{
+} // enable_restrictive_umask::~enable_restrictive_umask
+
+
// Local Variables:
// mode: C++
// fill-column: 76
=====================================
--
-- Stephe
- [Monotone-devel] patch for umask on MinGW,
Stephen Leake <=