|
27 | 27 | import java.io.OutputStream;
|
28 | 28 | import java.net.URI;
|
29 | 29 | import java.nio.file.AccessDeniedException;
|
| 30 | +import java.nio.file.CopyOption; |
30 | 31 | import java.nio.file.DirectoryNotEmptyException;
|
31 | 32 | import java.nio.file.FileAlreadyExistsException;
|
32 | 33 | import java.nio.file.Files;
|
33 | 34 | import java.nio.file.NoSuchFileException;
|
| 35 | +import java.nio.file.StandardCopyOption; |
34 | 36 | import java.nio.file.StandardOpenOption;
|
35 | 37 | import org.eclipse.core.filesystem.EFS;
|
36 | 38 | import org.eclipse.core.filesystem.IFileInfo;
|
@@ -149,6 +151,27 @@ public void copy(IFileStore destFile, int options, IProgressMonitor monitor) thr
|
149 | 151 | super.copy(destFile, options, monitor);
|
150 | 152 | }
|
151 | 153 |
|
| 154 | + private static final CopyOption[] NO_OVERWRITE = {StandardCopyOption.COPY_ATTRIBUTES}; |
| 155 | + private static final CopyOption[] OVERWRITE_EXISTING = {StandardCopyOption.COPY_ATTRIBUTES, StandardCopyOption.REPLACE_EXISTING}; |
| 156 | + |
| 157 | + @Override |
| 158 | + protected void copyFile(IFileInfo sourceInfo, IFileStore destination, int options, IProgressMonitor monitor) throws CoreException { |
| 159 | + if (destination instanceof LocalFile target) { |
| 160 | + try { |
| 161 | + boolean overwrite = (options & EFS.OVERWRITE) != 0; |
| 162 | + Files.copy(this.file.toPath(), target.file.toPath(), overwrite ? OVERWRITE_EXISTING : NO_OVERWRITE); |
| 163 | + } catch (FileAlreadyExistsException e) { |
| 164 | + Policy.error(EFS.ERROR_EXISTS, NLS.bind(Messages.fileExists, target.filePath), e); |
| 165 | + } catch (IOException e) { |
| 166 | + Policy.error(EFS.ERROR_WRITE, NLS.bind(Messages.failedCopy, this.filePath, target.filePath), e); |
| 167 | + } finally { |
| 168 | + IProgressMonitor.done(monitor); |
| 169 | + } |
| 170 | + } else { |
| 171 | + super.copyFile(sourceInfo, destination, options, monitor); |
| 172 | + } |
| 173 | + } |
| 174 | + |
152 | 175 | @Override
|
153 | 176 | public void delete(int options, IProgressMonitor monitor) throws CoreException {
|
154 | 177 | if (monitor == null)
|
|
0 commit comments