From d02a32360f9d1f5dd6202fe427c81df0803be32f Mon Sep 17 00:00:00 2001 From: Jason Duell Date: Thu, 28 Jul 2011 04:13:06 -0700 Subject: [PATCH] Bug 670911: Skip reset of NTFS ACLs when renaming file w/o changing directory. r=bsmedberg, sr=neil --- xpcom/io/nsLocalFileWin.cpp | 11 +++++++---- xpcom/io/nsLocalFileWin.h | 3 ++- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/xpcom/io/nsLocalFileWin.cpp b/xpcom/io/nsLocalFileWin.cpp index eec85fcd362..b020e61cbd2 100644 --- a/xpcom/io/nsLocalFileWin.cpp +++ b/xpcom/io/nsLocalFileWin.cpp @@ -1356,7 +1356,8 @@ nsLocalFile::GetVersionInfoField(const char* aField, nsAString& _retval) nsresult nsLocalFile::CopySingleFile(nsIFile *sourceFile, nsIFile *destParent, const nsAString &newName, - PRBool followSymlinks, PRBool move) + PRBool followSymlinks, PRBool move, + PRBool skipNtfsAclReset) { nsresult rv; nsAutoString filePath; @@ -1442,8 +1443,10 @@ nsLocalFile::CopySingleFile(nsIFile *sourceFile, nsIFile *destParent, if (!copyOK) // CopyFileEx and MoveFileEx return zero at failure. rv = ConvertWinError(GetLastError()); - else if (move) // Set security permissions to inherit from parent. + else if (move && !skipNtfsAclReset) { + // Set security permissions to inherit from parent. + // Note: propagates to all children: slow for big file trees PACL pOldDACL = NULL; PSECURITY_DESCRIPTOR pSD = NULL; ::GetNamedSecurityInfoW((LPWSTR)destPath.get(), SE_FILE_OBJECT, @@ -1476,7 +1479,6 @@ nsLocalFile::CopyMove(nsIFile *aParentDir, const nsAString &newName, PRBool foll if (!newParentDir) { // no parent was specified. We must rename. - if (newName.IsEmpty()) return NS_ERROR_INVALID_ARG; @@ -1542,7 +1544,8 @@ nsLocalFile::CopyMove(nsIFile *aParentDir, const nsAString &newName, PRBool foll if (move || !isDir || (isSymlink && !followSymlinks)) { // Copy/Move single file, or move a directory - rv = CopySingleFile(this, newParentDir, newName, followSymlinks, move); + rv = CopySingleFile(this, newParentDir, newName, followSymlinks, move, + !aParentDir); done = NS_SUCCEEDED(rv); // If we are moving a directory and that fails, fallback on directory // enumeration. See bug 231300 for details. diff --git a/xpcom/io/nsLocalFileWin.h b/xpcom/io/nsLocalFileWin.h index 658f74279e9..8811c0a4cb5 100644 --- a/xpcom/io/nsLocalFileWin.h +++ b/xpcom/io/nsLocalFileWin.h @@ -123,7 +123,8 @@ private: PRBool followSymlinks, PRBool move); nsresult CopySingleFile(nsIFile *source, nsIFile* dest, const nsAString &newName, - PRBool followSymlinks, PRBool move); + PRBool followSymlinks, PRBool move, + PRBool skipNtfsAclReset = PR_FALSE); nsresult SetModDate(PRInt64 aLastModifiedTime, const PRUnichar *filePath); nsresult HasFileAttribute(DWORD fileAttrib, PRBool *_retval);