Skip to content

Commit 0b5096e

Browse files
committed
CB-7602: Fix isCopyOnItself logic
It should not treat /a/bc/ as a subdirectory of /a/b/
1 parent 8ef744d commit 0b5096e

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

src/android/LocalFilesystem.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -305,11 +305,7 @@ private boolean isCopyOnItself(String src, String dest) {
305305
// This weird test is to determine if we are copying or moving a directory into itself.
306306
// Copy /sdcard/myDir to /sdcard/myDir-backup is okay but
307307
// Copy /sdcard/myDir to /sdcard/myDir/backup should throw an INVALID_MODIFICATION_ERR
308-
if (dest.startsWith(src) && dest.indexOf(File.separator, src.length() - 1) != -1) {
309-
return true;
310-
}
311-
312-
return false;
308+
return dest.equals(src) || dest.startsWith(src + File.separator);
313309
}
314310

315311
/**

tests/tests.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1599,6 +1599,24 @@ exports.defineAutoTests = function () {
15991599
});
16001600
}, failed.bind(null, done, 'createDirectory - Error creating directory : ' + srcDir));
16011601
});
1602+
it("file.spec.130 moveTo: directory into similar directory", function (done) {
1603+
var srcDir = "entry.move.dis.srcDir",
1604+
dstDir = "entry.move.dis.srcDir-backup",
1605+
srcPath = joinURL(root.fullPath, srcDir);
1606+
// create a new directory entry to kick off it
1607+
createDirectory(srcDir, function (srcDirEntry) {
1608+
deleteEntry(dstDir, function () {
1609+
createDirectory(dstDir, function (dstDirEntry) {
1610+
// move source directory into itself
1611+
srcDirEntry.moveTo(dstDirEntry, 'file', function (newDirEntry) {
1612+
expect(newDirEntry).toBeDefined();
1613+
deleteEntry(dstDir);
1614+
done();
1615+
}, failed.bind(null, done, 'directory.moveTo - Error moving a directory into a similarly-named directory: ' + srcDir));
1616+
}, failed.bind(null, done, 'createDirectory - Error creating directory : ' + dstDir));
1617+
}, failed.bind(null, done, 'deleteEntry - Error deleting directory : ' + dstDir));
1618+
}, failed.bind(null, done, 'createDirectory - Error creating directory : ' + srcDir));
1619+
});
16021620
it("file.spec.72 moveTo: file onto itself", function (done) {
16031621
var file1 = "entry.move.fos.file1",
16041622
filePath = joinURL(root.fullPath, file1);

0 commit comments

Comments
 (0)