summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjan.nijtmans <nijtmans@users.sourceforge.net>2014-03-26 14:34:56 (GMT)
committerjan.nijtmans <nijtmans@users.sourceforge.net>2014-03-26 14:34:56 (GMT)
commit07ba2fc47f5d9c888ccb11ca3666f215159b5f45 (patch)
tree0e6cfb17fc9375d1986157c9b4d1f8887eccf884
parent3b6523dd1f6ce2e08932508cf276ca55d04872e6 (diff)
downloadtcl-07ba2fc47f5d9c888ccb11ca3666f215159b5f45.zip
tcl-07ba2fc47f5d9c888ccb11ca3666f215159b5f45.tar.gz
tcl-07ba2fc47f5d9c888ccb11ca3666f215159b5f45.tar.bz2
Only write back file attributes if any of them really changed.rfe_b42b208ba4
-rw-r--r--unix/tclUnixFCmd.c23
-rw-r--r--win/tclWinFCmd.c7
2 files changed, 15 insertions, 15 deletions
diff --git a/unix/tclUnixFCmd.c b/unix/tclUnixFCmd.c
index 259c7e5..3b1b6ca 100644
--- a/unix/tclUnixFCmd.c
+++ b/unix/tclUnixFCmd.c
@@ -2289,11 +2289,12 @@ StatError(
}
static WCHAR *
-winPathFromNative(
- const char *native)
+winPathFromObj(
+ Tcl_Obj *fileName)
{
- int size;
- WCHAR *winPath;
+ int size;
+ const char *native = Tcl_FSGetNativePath(fileName);
+ WCHAR *winPath;
size = cygwin_conv_path(1, native, NULL, 0);
winPath = ckalloc(size);
@@ -2330,8 +2331,7 @@ GetUnixFileAttributes(
Tcl_Obj **attributePtrPtr) /* A pointer to return the object with. */
{
int fileAttributes;
- const char *native = Tcl_FSGetNativePath(fileName);
- WCHAR *winPath = winPathFromNative(native);
+ WCHAR *winPath = winPathFromObj(fileName);
fileAttributes = GetFileAttributesW(winPath);
ckfree(winPath);
@@ -2369,18 +2369,16 @@ SetUnixFileAttributes(
Tcl_Obj *fileName, /* The name of the file (UTF-8). */
Tcl_Obj *attributePtr) /* The attribute to set. */
{
- int yesNo, fileAttributes;
- const char *native;
+ int yesNo, fileAttributes, old;
WCHAR *winPath;
if (Tcl_GetBooleanFromObj(interp, attributePtr, &yesNo) != TCL_OK) {
return TCL_ERROR;
}
- native = Tcl_FSGetNativePath(fileName);
- winPath = winPathFromNative(native);
+ winPath = winPathFromObj(fileName);
- fileAttributes = GetFileAttributesW(winPath);
+ fileAttributes = old = GetFileAttributesW(winPath);
if (fileAttributes == -1) {
ckfree(winPath);
@@ -2394,7 +2392,8 @@ SetUnixFileAttributes(
fileAttributes &= ~attributeArray[objIndex];
}
- if (!SetFileAttributesW(winPath, fileAttributes)) {
+ if ((fileAttributes != old)
+ && !SetFileAttributesW(winPath, fileAttributes)) {
ckfree(winPath);
StatError(interp, fileName);
return TCL_ERROR;
diff --git a/win/tclWinFCmd.c b/win/tclWinFCmd.c
index 2700cb3..f14d9ff 100644
--- a/win/tclWinFCmd.c
+++ b/win/tclWinFCmd.c
@@ -1825,12 +1825,12 @@ SetWinFileAttributes(
Tcl_Obj *fileName, /* The name of the file. */
Tcl_Obj *attributePtr) /* The new value of the attribute. */
{
- DWORD fileAttributes;
+ DWORD fileAttributes, old;
int yesNo, result;
const TCHAR *nativeName;
nativeName = Tcl_FSGetNativePath(fileName);
- fileAttributes = GetFileAttributes(nativeName);
+ fileAttributes = old = GetFileAttributes(nativeName);
if (fileAttributes == 0xffffffff) {
StatError(interp, fileName);
@@ -1848,7 +1848,8 @@ SetWinFileAttributes(
fileAttributes &= ~(attributeArray[objIndex]);
}
- if (!SetFileAttributes(nativeName, fileAttributes)) {
+ if ((fileAttributes != old)
+ && !SetFileAttributes(nativeName, fileAttributes)) {
StatError(interp, fileName);
return TCL_ERROR;
}