diff options
| author | Sergey Prigogin | 2016-02-15 04:43:47 +0000 |
|---|---|---|
| committer | Sergey Prigogin | 2016-02-15 19:55:11 +0000 |
| commit | b8088ae7aa4bc6fa23a9e5dfc3836ad776e8ff3b (patch) | |
| tree | de22adb2f9ea079f8dd2bbcab92d042f21db06d6 | |
| parent | 4a4b4291b3ff2f6ea68081dc61321c779808acf4 (diff) | |
| download | eclipse.platform.resources-b8088ae7aa4bc6fa23a9e5dfc3836ad776e8ff3b.tar.gz eclipse.platform.resources-b8088ae7aa4bc6fa23a9e5dfc3836ad776e8ff3b.tar.xz eclipse.platform.resources-b8088ae7aa4bc6fa23a9e5dfc3836ad776e8ff3b.zip | |
Code streamlining.I20160216-1400I20160216-0800
Change-Id: I3743a74e509318d64de1b0c4395b514c38ee79c8
| -rw-r--r-- | bundles/org.eclipse.core.filesystem/src/org/eclipse/core/internal/filesystem/local/LocalFile.java | 46 |
1 files changed, 27 insertions, 19 deletions
diff --git a/bundles/org.eclipse.core.filesystem/src/org/eclipse/core/internal/filesystem/local/LocalFile.java b/bundles/org.eclipse.core.filesystem/src/org/eclipse/core/internal/filesystem/local/LocalFile.java index 4c6acb7aa..7b34b5cec 100644 --- a/bundles/org.eclipse.core.filesystem/src/org/eclipse/core/internal/filesystem/local/LocalFile.java +++ b/bundles/org.eclipse.core.filesystem/src/org/eclipse/core/internal/filesystem/local/LocalFile.java @@ -16,6 +16,8 @@ package org.eclipse.core.internal.filesystem.local; import java.io.*; import java.net.URI; +import java.nio.file.DirectoryNotEmptyException; +import java.nio.file.Files; import org.eclipse.core.filesystem.*; import org.eclipse.core.filesystem.URIUtil; import org.eclipse.core.filesystem.provider.FileInfo; @@ -208,13 +210,14 @@ public class LocalFile extends FileStore { * to optimize java.io.File object creation. */ private boolean internalDelete(File target, String pathToDelete, MultiStatus status, IProgressMonitor monitor) { - //first try to delete - this should succeed for files and symbolic links to directories if (monitor.isCanceled()) { throw new OperationCanceledException(); } - if (target.delete() || !target.exists()) + try { + // First try to delete - this should succeed for files and symbolic links to directories. + Files.deleteIfExists(target.toPath()); return true; - if (target.isDirectory()) { + } catch (DirectoryNotEmptyException e) { monitor.subTask(NLS.bind(Messages.deleting, target)); String[] list = target.list(); if (list == null) @@ -225,35 +228,40 @@ public class LocalFile extends FileStore { if (monitor.isCanceled()) { throw new OperationCanceledException(); } - //optimized creation of child path object - StringBuffer childBuffer = new StringBuffer(parentLength + list[i].length() + 1); + // Optimized creation of child path object + StringBuilder childBuffer = new StringBuilder(parentLength + list[i].length() + 1); childBuffer.append(pathToDelete); childBuffer.append(File.separatorChar); childBuffer.append(list[i]); String childName = childBuffer.toString(); - // try best effort on all children so put logical OR at end + // Try best effort on all children so put logical OR at end. failedRecursive = !internalDelete(new java.io.File(childName), childName, status, monitor) || failedRecursive; monitor.worked(1); } try { - // don't try to delete the root if one of the children failed - if (!failedRecursive && target.delete()) + // Don't try to delete the root if one of the children failed. + if (!failedRecursive && Files.deleteIfExists(target.toPath())) return true; - } catch (Exception e) { - // we caught a runtime exception so log it + } catch (Exception e1) { + // We caught a runtime exception so log it. String message = NLS.bind(Messages.couldnotDelete, target.getAbsolutePath()); - status.add(new Status(IStatus.ERROR, Policy.PI_FILE_SYSTEM, EFS.ERROR_DELETE, message, e)); + status.add(new Status(IStatus.ERROR, Policy.PI_FILE_SYSTEM, EFS.ERROR_DELETE, message, e1)); return false; } + // If we got this far, we failed. + String message = null; + if (fetchInfo().getAttribute(EFS.ATTRIBUTE_READ_ONLY)) { + message = NLS.bind(Messages.couldnotDeleteReadOnly, target.getAbsolutePath()); + } else { + message = NLS.bind(Messages.couldnotDelete, target.getAbsolutePath()); + } + status.add(new Status(IStatus.ERROR, Policy.PI_FILE_SYSTEM, EFS.ERROR_DELETE, message, null)); + return false; + } catch (IOException e) { + String message = NLS.bind(Messages.couldnotDelete, target.getAbsolutePath()); + status.add(new Status(IStatus.ERROR, Policy.PI_FILE_SYSTEM, EFS.ERROR_DELETE, message, e)); + return false; } - //if we got this far, we failed - String message = null; - if (fetchInfo().getAttribute(EFS.ATTRIBUTE_READ_ONLY)) - message = NLS.bind(Messages.couldnotDeleteReadOnly, target.getAbsolutePath()); - else - message = NLS.bind(Messages.couldnotDelete, target.getAbsolutePath()); - status.add(new Status(IStatus.ERROR, Policy.PI_FILE_SYSTEM, EFS.ERROR_DELETE, message, null)); - return false; } @Override |
