Skip to content

Commit ec4235b

Browse files
ptziegleriloveeclipse
authored andcommitted
Bug 567104 - Export Error if a File should be overriden
The change done in 9c6c551 introduces a regression due to which it is no longer possible to export a file to the file system, if the file already exists. When copying a file using the Files API, one needs to explicitly set the REPLACE_EXISTING flag, in order to overwrite the target file, otherwise a FileAreadyExistsException is thrown. Note: The "writeFile" method is only called when the user explicitly chose to overwrite the existing file. It is therefore safe to always set this flag.
1 parent 61ce530 commit ec4235b

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/wizards/datatransfer/FileSystemExporter.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2000, 2015 IBM Corporation and others.
2+
* Copyright (c) 2000, 2025 IBM Corporation and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -84,7 +84,7 @@ protected void writeFile(IFile file, IPath destinationPath)
8484
if (sourceLocation != null) {
8585
// local file, preserve attributes
8686
Files.copy(sourceLocation.toFile().toPath(), destinationPath.toFile().toPath(),
87-
StandardCopyOption.COPY_ATTRIBUTES, LinkOption.NOFOLLOW_LINKS);
87+
StandardCopyOption.REPLACE_EXISTING, StandardCopyOption.COPY_ATTRIBUTES, LinkOption.NOFOLLOW_LINKS);
8888
} else {
8989
// virtual file system, transfer stream
9090
try (InputStream is = new BufferedInputStream(file.getContents(false))) {

tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/datatransfer/ExportFileSystemOperationTest.java

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2005, 2017 IBM Corporation and others.
2+
* Copyright (c) 2005, 2025 IBM Corporation and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -217,6 +217,9 @@ public void testExportOverwrite() throws Exception {
217217
operation.setCreateLeadupStructure(false);
218218
openTestWindow().run(true, true, operation);
219219

220+
// overwrite successful?
221+
IStatus status = operation.getStatus();
222+
assertTrue(status.toString(), status.isOK());
220223
// +1 for .settings
221224
verifyFolders(directoryNames.length + 1);
222225
}

0 commit comments

Comments
 (0)