summaryrefslogtreecommitdiff
path: root/cpp/src/IcePatch/Util.cpp
diff options
context:
space:
mode:
authorMark Spruiell <mes@zeroc.com>2004-10-27 19:48:20 +0000
committerMark Spruiell <mes@zeroc.com>2004-10-27 19:48:20 +0000
commitf6668e7f576abbb80f955d9beadfd630109566c7 (patch)
tree164ba2009bd3d5304dbe64a74035da873c80eb2b /cpp/src/IcePatch/Util.cpp
parentFixes to code generation for nested sequences. (diff)
downloadice-f6668e7f576abbb80f955d9beadfd630109566c7.tar.bz2
ice-f6668e7f576abbb80f955d9beadfd630109566c7.tar.xz
ice-f6668e7f576abbb80f955d9beadfd630109566c7.zip
utime workaround for NT/2000/XP
Diffstat (limited to 'cpp/src/IcePatch/Util.cpp')
-rw-r--r--cpp/src/IcePatch/Util.cpp78
1 files changed, 63 insertions, 15 deletions
diff --git a/cpp/src/IcePatch/Util.cpp b/cpp/src/IcePatch/Util.cpp
index 00686aa7356..95718f2ea32 100644
--- a/cpp/src/IcePatch/Util.cpp
+++ b/cpp/src/IcePatch/Util.cpp
@@ -229,6 +229,21 @@ IcePatch::getFileInfo(const string& path, bool exceptionIfNotExist, const Ice::L
result.size = buf.st_size;
result.time = buf.st_mtime;
+
+ if(S_ISDIR(buf.st_mode))
+ {
+ result.type = FileTypeDirectory;
+ }
+ else if(S_ISREG(buf.st_mode))
+ {
+ result.type = FileTypeRegular;
+ }
+ else
+ {
+ FileAccessException ex;
+ ex.reason = "file type of `" + path + "' is not supported";
+ throw ex;
+ }
if(IceUtil::Time::seconds(result.time) <= IceUtil::Time::now())
{
@@ -271,7 +286,54 @@ IcePatch::getFileInfo(const string& path, bool exceptionIfNotExist, const Ice::L
//
// Now we reset the time of the file to the current time.
+ //
+ // Note that utime() fails for directories in Windows, so we
+ // have to use a workaround on NT/2000/XP.
+ //
+ // See http://www.cygwin.com/ml/cygwin/1997-12/msg00350.html
//
+#if defined(_WIN32) && defined(FILE_FLAG_BACKUP_SEMANTICS)
+ if(result.type == FileTypeDirectory)
+ {
+ HANDLE hDir = CreateFile(
+ path.c_str(),
+ GENERIC_READ,
+ FILE_SHARE_READ|FILE_SHARE_DELETE,
+ NULL,
+ OPEN_EXISTING,
+ FILE_FLAG_BACKUP_SEMANTICS,
+ NULL
+ );
+ if(hDir == NULL)
+ {
+ FileAccessException ex;
+ ex.reason = "cannot access `" + path + "'";
+ throw ex;
+ }
+
+ FILETIME now;
+ GetSystemTimeAsFileTime(&now);
+
+ if(!SetFileTime(hDir, &now, &now, &now))
+ {
+ FileAccessException ex;
+ ex.reason = "cannot set file time for `" + path + "'";
+ throw ex;
+ }
+ }
+ else
+ {
+ if(::utime(path.c_str(), 0) == -1)
+ {
+ if(errno != ENOENT)
+ {
+ FileAccessException ex;
+ ex.reason = "cannot utime `" + path + "': " + strerror(errno);
+ throw ex;
+ }
+ }
+ }
+#else
if(::utime(path.c_str(), 0) == -1)
{
if(errno != ENOENT)
@@ -281,26 +343,12 @@ IcePatch::getFileInfo(const string& path, bool exceptionIfNotExist, const Ice::L
throw ex;
}
}
+#endif
//
// Now we do the loop again.
//
}
-
- if(S_ISDIR(buf.st_mode))
- {
- result.type = FileTypeDirectory;
- }
- else if(S_ISREG(buf.st_mode))
- {
- result.type = FileTypeRegular;
- }
- else
- {
- FileAccessException ex;
- ex.reason = "file type of `" + path + "' is not supported";
- throw ex;
- }
return result;
}