fixed moving to network drives
This commit is contained in:
parent
d809d9968c
commit
93abc7185c
@ -138,7 +138,11 @@ public class FileOperations {
|
|||||||
callback.onProgress(currentItem[0], totalItems, source.getFileName().toString());
|
callback.onProgress(currentItem[0], totalItems, source.getFileName().toString());
|
||||||
callback.onFileProgress(fileSize, fileSize);
|
callback.onFileProgress(fileSize, fileSize);
|
||||||
}
|
}
|
||||||
Files.setLastModifiedTime(target, Files.getLastModifiedTime(source));
|
try {
|
||||||
|
Files.setLastModifiedTime(target, Files.getLastModifiedTime(source));
|
||||||
|
} catch (IOException e) {
|
||||||
|
// Ignore failure to set time on some filesystems (like network mounts)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void copySymlink(Path source, Path target, long totalItems, long[] currentItem, ProgressCallback callback) throws IOException {
|
private static void copySymlink(Path source, Path target, long totalItems, long[] currentItem, ProgressCallback callback) throws IOException {
|
||||||
@ -289,27 +293,36 @@ public class FileOperations {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (callback != null) {
|
long itemCount = countItems(source.toPath());
|
||||||
// For move, we report the start of moving the item.
|
|
||||||
// Note: if it's a directory, this counts as multiple items in totalItems,
|
|
||||||
// but Files.move will do it in one go. We increment currentItem by the actual count.
|
|
||||||
long itemCount = countItems(source.toPath());
|
|
||||||
currentItem[0] += itemCount;
|
|
||||||
callback.onProgress(currentItem[0], totalItems, source.getName());
|
|
||||||
}
|
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
try {
|
try {
|
||||||
Files.move(source.toPath(), target.toPath(), StandardCopyOption.REPLACE_EXISTING);
|
Files.move(source.toPath(), target.toPath(), StandardCopyOption.REPLACE_EXISTING);
|
||||||
|
currentItem[0] += itemCount;
|
||||||
|
if (callback != null) {
|
||||||
|
callback.onProgress(currentItem[0], totalItems, source.getName());
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
if (callback != null) {
|
// Fallback for cross-device moves (e.g., to network/Samba mounts)
|
||||||
ErrorResponse res = callback.onError(source, e);
|
try {
|
||||||
if (res == ErrorResponse.ABORT) throw e;
|
if (source.isDirectory()) {
|
||||||
if (res == ErrorResponse.RETRY) continue;
|
copyDirectory(source.toPath(), target.toPath(), totalItems, currentItem, callback, globalResponse);
|
||||||
|
currentItem[0]++; // For the directory itself which copyDirectory skips
|
||||||
|
deleteDirectoryInternal(source.toPath());
|
||||||
|
} else {
|
||||||
|
copyFileWithProgress(source.toPath(), target.toPath(), totalItems, currentItem, callback);
|
||||||
|
Files.delete(source.toPath());
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
} else {
|
} catch (IOException ex) {
|
||||||
throw e;
|
if (callback != null) {
|
||||||
|
ErrorResponse res = callback.onError(source, ex);
|
||||||
|
if (res == ErrorResponse.ABORT) throw ex;
|
||||||
|
if (res == ErrorResponse.RETRY) continue;
|
||||||
|
break;
|
||||||
|
} else {
|
||||||
|
throw ex;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user