Skip to content

Commit 6def298

Browse files
bobowenyjugl
authored andcommitted
Bug 1980886 p1 - Refactor CopySingleFile to better reflect its usage and behaviour. r=yjuglaret
Differential Revision: https://phabricator.services.mozilla.com/D266681
1 parent 72eb58b commit 6def298

File tree

2 files changed

+19
-15
lines changed

2 files changed

+19
-15
lines changed

xpcom/io/nsLocalFileWin.cpp

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1740,9 +1740,9 @@ static bool IsRemoteFilePath(LPCWSTR aPath, bool& aRemote) {
17401740
return true;
17411741
}
17421742

1743-
nsresult nsLocalFile::CopySingleFile(nsIFile* aSourceFile, nsIFile* aDestParent,
1744-
const nsAString& aNewName,
1745-
uint32_t aOptions) {
1743+
nsresult nsLocalFile::MoveOrCopyAsSingleFileOrDir(nsIFile* aDestParent,
1744+
const nsAString& aNewName,
1745+
uint32_t aOptions) {
17461746
nsresult rv = NS_OK;
17471747
nsAutoString filePath;
17481748

@@ -1762,31 +1762,28 @@ nsresult nsLocalFile::CopySingleFile(nsIFile* aSourceFile, nsIFile* aDestParent,
17621762

17631763
if (aNewName.IsEmpty()) {
17641764
nsAutoString aFileName;
1765-
aSourceFile->GetLeafName(aFileName);
1765+
GetLeafName(aFileName);
17661766
destPath.Append(aFileName);
17671767
} else {
17681768
destPath.Append(aNewName);
17691769
}
17701770

17711771
if (aOptions & FollowSymlinks) {
1772-
rv = aSourceFile->GetTarget(filePath);
1772+
rv = GetTarget(filePath);
17731773
if (filePath.IsEmpty()) {
1774-
rv = aSourceFile->GetPath(filePath);
1774+
rv = GetPath(filePath);
17751775
}
17761776
} else {
1777-
rv = aSourceFile->GetPath(filePath);
1777+
rv = GetPath(filePath);
17781778
}
17791779

17801780
if (NS_FAILED(rv)) {
17811781
return rv;
17821782
}
17831783

17841784
#ifdef DEBUG
1785-
nsCOMPtr<nsILocalFileWin> srcWinFile = do_QueryInterface(aSourceFile);
1786-
MOZ_ASSERT(srcWinFile);
1787-
17881785
bool srcUseDOSDevicePathSyntax;
1789-
srcWinFile->GetUseDOSDevicePathSyntax(&srcUseDOSDevicePathSyntax);
1786+
GetUseDOSDevicePathSyntax(&srcUseDOSDevicePathSyntax);
17901787

17911788
nsCOMPtr<nsILocalFileWin> destWinFile = do_QueryInterface(aDestParent);
17921789
MOZ_ASSERT(destWinFile);
@@ -1993,7 +1990,7 @@ nsresult nsLocalFile::CopyMove(nsIFile* aParentDir, const nsAString& aNewName,
19931990
if (!aParentDir) {
19941991
aOptions |= SkipNtfsAclReset;
19951992
}
1996-
rv = CopySingleFile(this, newParentDir, aNewName, aOptions);
1993+
rv = MoveOrCopyAsSingleFileOrDir(newParentDir, aNewName, aOptions);
19971994
done = NS_SUCCEEDED(rv);
19981995
// If we are moving a directory and that fails, fallback on directory
19991996
// enumeration. See bug 231300 for details.
@@ -2247,7 +2244,7 @@ nsLocalFile::RenameTo(nsIFile* aNewParentDir, const nsAString& aNewName) {
22472244
options |= SkipNtfsAclReset;
22482245
}
22492246
// Move single file, or move a directory
2250-
return CopySingleFile(this, targetParentDir, aNewName, options);
2247+
return MoveOrCopyAsSingleFileOrDir(targetParentDir, aNewName, options);
22512248
}
22522249

22532250
NS_IMETHODIMP

xpcom/io/nsLocalFileWin.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,15 @@ class nsLocalFile final : public nsILocalFileWin {
108108

109109
nsresult CopyMove(nsIFile* aNewParentDir, const nsAString& aNewName,
110110
uint32_t aOptions);
111-
nsresult CopySingleFile(nsIFile* aSource, nsIFile* aDest,
112-
const nsAString& aNewName, uint32_t aOptions);
111+
/**
112+
* Moves or copies this file or directory as a single entity.
113+
* @param aDest the destination directory
114+
* @param aNewName optional new name
115+
* @param aOptions CopyFileOption flags
116+
*/
117+
nsresult MoveOrCopyAsSingleFileOrDir(nsIFile* aDest,
118+
const nsAString& aNewName,
119+
uint32_t aOptions);
113120

114121
enum class TimeField { AccessedTime, ModifiedTime };
115122

0 commit comments

Comments
 (0)