Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 47122 Details for
Bug 125524
PublishUtil.createZipFile() has problem deleting file
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
[patch]
Patch to rewrite files during publish if they can't be deleted
Publish_File_Rewrite_Patch.txt (text/plain), 14.71 KB, created by
Larry Isaacs
on 2006-07-31 20:37:50 EDT
(
hide
)
Description:
Patch to rewrite files during publish if they can't be deleted
Filename:
MIME Type:
Creator:
Larry Isaacs
Created:
2006-07-31 20:37:50 EDT
Size:
14.71 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.jst.server.core >Index: sjavacore/org/eclipse/jst/server/core/PublishUtil.java >=================================================================== >RCS file: /cvsroot/webtools/jst/components/server/plugins/org.eclipse.jst.server.core/sjavacore/org/eclipse/jst/server/core/PublishUtil.java,v >retrieving revision 1.17 >diff -u -r1.17 PublishUtil.java >--- sjavacore/org/eclipse/jst/server/core/PublishUtil.java 26 Jul 2006 15:29:44 -0000 1.17 >+++ sjavacore/org/eclipse/jst/server/core/PublishUtil.java 28 Jul 2006 12:51:13 -0000 >@@ -158,7 +158,19 @@ > * @throws CoreException > */ > public static void createZipFile(IModuleResource[] resources, IPath zipPath) throws CoreException { >- IStatus[] status = PublishUtil.publishZip(resources, zipPath, null); >+ createZipFile(resources, zipPath, false); >+ } >+ >+ /** >+ * Creates a new zip file containing the given module resources. Deletes the existing file >+ * (and doesn't create a new one) if resources is null or empty. >+ * >+ * @param resources >+ * @param zipPath >+ * @throws CoreException >+ */ >+ public static void createZipFile(IModuleResource[] resources, IPath zipPath, boolean allowRewrite) throws CoreException { >+ IStatus[] status = PublishUtil.publishZip(resources, zipPath, allowRewrite, null); > if (status != null && status.length > 0) > throw new CoreException(status[0]); > } >@@ -171,7 +183,7 @@ > * @param ts timestamp > * @throws CoreException if anything goes wrong > */ >- private static void copyFile(InputStream in, IPath to, long ts, IModuleFile mf) throws CoreException { >+ private static void copyFile(InputStream in, IPath to, long ts, boolean allowRewrite, IModuleFile mf) throws CoreException { > OutputStream out = null; > > File tempFile = null; >@@ -191,7 +203,7 @@ > out.close(); > out = null; > >- moveTempFile(tempFile, file); >+ moveTempFile(tempFile, file, allowRewrite); > > if (ts != IResource.NULL_STAMP && ts != 0) > file.setLastModified(ts); >@@ -281,6 +293,21 @@ > * @return a possibly-empty array of error and warning status > */ > public static IStatus[] publishSmart(IModuleResource[] resources, IPath path, IProgressMonitor monitor) { >+ return publishSmart(resources, path, false, monitor); >+ } >+ >+ /** >+ * Smart copy the given module resources to the given path. >+ * >+ * @param resources an array of module resources >+ * @param path an external path to copy to >+ * @param allowRewrite if <code>true</code>, attempt to rewrite the >+ * existing file if it can't be deleted >+ * @param monitor a progress monitor, or <code>null</code> if progress >+ * reporting and cancellation are not desired >+ * @return a possibly-empty array of error and warning status >+ */ >+ public static IStatus[] publishSmart(IModuleResource[] resources, IPath path, boolean allowRewrite, IProgressMonitor monitor) { > if (resources == null) > return new IStatus[0]; > >@@ -370,7 +397,7 @@ > > if (copy) { > try { >- copyFile(mf, toPath); >+ copyFile(mf, toPath, allowRewrite); > } catch (CoreException ce) { > status.add(ce.getStatus()); > } >@@ -380,7 +407,7 @@ > IModuleFolder folder = (IModuleFolder) current; > IModuleResource[] children = folder.members(); > monitor.subTask(NLS.bind(Messages.copyingTask, new String[] {resources[i].getName(), current.getName()})); >- IStatus[] stat = publishSmart(children, toPath, ProgressUtil.getSubMonitorFor(monitor, dw)); >+ IStatus[] stat = publishSmart(children, toPath, allowRewrite, ProgressUtil.getSubMonitorFor(monitor, dw)); > addArrayToList(status, stat); > } > if (monitor.isCanceled()) >@@ -404,6 +431,20 @@ > * @return a possibly-empty array of error and warning status > */ > public static IStatus[] publishDelta(IModuleResourceDelta delta, IPath path, IProgressMonitor monitor) { >+ return publishDelta(delta, path, false, monitor); >+ } >+ /** >+ * Handle a delta publish. >+ * >+ * @param delta a module resource delta >+ * @param path the path to publish to >+ * @param allowRewrite if <code>true</code>, attempt to rewrite the >+ * existing resources if they can't be deleted >+ * @param monitor a progress monitor, or <code>null</code> if progress >+ * reporting and cancellation are not desired >+ * @return a possibly-empty array of error and warning status >+ */ >+ public static IStatus[] publishDelta(IModuleResourceDelta delta, IPath path, boolean allowRewrite, IProgressMonitor monitor) { > List status = new ArrayList(); > > IModuleResource resource = delta.getModuleResource(); >@@ -420,7 +461,7 @@ > if (!f.exists()) > f.mkdirs(); > >- copyFile(file, path2); >+ copyFile(file, path2, allowRewrite); > } > } catch (CoreException ce) { > status.add(ce.getStatus()); >@@ -453,7 +494,7 @@ > IModuleResourceDelta[] childDeltas = delta.getAffectedChildren(); > int size = childDeltas.length; > for (int i = 0; i < size; i++) { >- IStatus[] stat = publishDelta(childDeltas[i], path, monitor); >+ IStatus[] stat = publishDelta(childDeltas[i], path, allowRewrite, monitor); > addArrayToList(status, stat); > } > IStatus[] stat = new IStatus[status.size()]; >@@ -468,12 +509,12 @@ > throw new CoreException(new Status(IStatus.ERROR, JavaServerPlugin.PLUGIN_ID, 0, NLS.bind(Messages.errorDeleting, path2), null)); > } > >- private static void copyFile(IModuleFile mf, IPath path) throws CoreException { >+ private static void copyFile(IModuleFile mf, IPath path, boolean allowRewrite) throws CoreException { > Trace.trace(Trace.PUBLISHING, "Copying: " + mf.getName() + " to " + path.toString()); > > IFile file = (IFile) mf.getAdapter(IFile.class); > if (file != null) >- copyFile(file.getContents(), path, file.getLocalTimeStamp(), mf); >+ copyFile(file.getContents(), path, file.getLocalTimeStamp(), allowRewrite, mf); > else { > File file2 = (File) mf.getAdapter(File.class); > InputStream in = null; >@@ -482,7 +523,7 @@ > } catch (IOException e) { > throw new CoreException(new Status(IStatus.ERROR, JavaServerPlugin.PLUGIN_ID, 0, NLS.bind(Messages.errorReading, file2.getAbsolutePath()), e)); > } >- copyFile(in, path, file2.lastModified(), mf); >+ copyFile(in, path, file2.lastModified(), allowRewrite, mf); > } > } > >@@ -496,13 +537,27 @@ > * @return a possibly-empty array of error and warning status > */ > public static IStatus[] publishFull(IModuleResource[] resources, IPath path, IProgressMonitor monitor) { >+ return publishFull(resources, path, false, monitor); >+ } >+ /** >+ * Publish the given module resources to the given path. >+ * >+ * @param resources an array of module resources >+ * @param path a path to publish to >+ * @param allowRewrite if <code>true</code>, attempt to rewrite the >+ * existing resources if they can't be deleted >+ * @param monitor a progress monitor, or <code>null</code> if progress >+ * reporting and cancellation are not desired >+ * @return a possibly-empty array of error and warning status >+ */ >+ public static IStatus[] publishFull(IModuleResource[] resources, IPath path, boolean allowRewrite, IProgressMonitor monitor) { > if (resources == null) > return new IStatus[0]; > > List status = new ArrayList(); > int size = resources.length; > for (int i = 0; i < size; i++) { >- IStatus[] stat = copy(resources[i], path, monitor); >+ IStatus[] stat = copy(resources[i], path, allowRewrite, monitor); > addArrayToList(status, stat); > } > >@@ -511,12 +566,12 @@ > return stat; > } > >- private static IStatus[] copy(IModuleResource resource, IPath path, IProgressMonitor monitor) { >+ private static IStatus[] copy(IModuleResource resource, IPath path, boolean allowRewrite, IProgressMonitor monitor) { > Trace.trace(Trace.PUBLISHING, "Copying: " + resource.getName() + " to " + path.toString()); > List status = new ArrayList(); > if (resource instanceof IModuleFolder) { > IModuleFolder folder = (IModuleFolder) resource; >- IStatus[] stat = publishFull(folder.members(), path, monitor); >+ IStatus[] stat = publishFull(folder.members(), path, allowRewrite, monitor); > addArrayToList(status, stat); > } else { > IModuleFile mf = (IModuleFile) resource; >@@ -525,7 +580,7 @@ > if (!f.exists()) > f.mkdirs(); > try { >- copyFile(mf, path); >+ copyFile(mf, path, allowRewrite); > } catch (CoreException ce) { > status.add(ce.getStatus()); > } >@@ -546,6 +601,22 @@ > * @return a possibly-empty array of error and warning status > */ > public static IStatus[] publishZip(IModuleResource[] resources, IPath path, IProgressMonitor monitor) { >+ return publishZip(resources, path, false, monitor); >+ } >+ >+ /** >+ * Creates a new zip file containing the given module resources. Deletes the existing file >+ * (and doesn't create a new one) if resources is null or empty. >+ * >+ * @param resources an array of module resources >+ * @param path the path where the zip file should be created >+ * @param allowRewrite if <code>true</code>, attempt to rewrite the >+ * existing zip file if it can't be deleted >+ * @param monitor a progress monitor, or <code>null</code> if progress >+ * reporting and cancellation are not desired >+ * @return a possibly-empty array of error and warning status >+ */ >+ public static IStatus[] publishZip(IModuleResource[] resources, IPath path, boolean allowRewrite, IProgressMonitor monitor) { > if (resources == null || resources.length == 0) { > // should also check if resources consists of all empty directories > File file = path.toFile(); >@@ -565,7 +636,7 @@ > addZipEntries(zout, resources); > zout.close(); > >- moveTempFile(tempFile, file); >+ moveTempFile(tempFile, file, allowRewrite); > } catch (CoreException e) { > return new IStatus[] { e.getStatus() }; > } catch (Exception e) { >@@ -650,11 +721,29 @@ > * > * @param tempFile > * @param file >+ * @param allowRewrite if <code>true</code>, attempt to rewrite an existing >+ * file with the tempFile contents if the existing file can't be deleted >+ * to permit the move > * @throws CoreException > */ >- private static void moveTempFile(File tempFile, File file) throws CoreException { >+ private static void moveTempFile(File tempFile, File file, boolean allowRewrite) throws CoreException { > if (file.exists()) { >- if (!safeDelete(file)) { >+ if (!safeDelete(file, allowRewrite ? 1 : 10)) { >+ if (allowRewrite) { >+ try { >+ InputStream in = new FileInputStream(tempFile); >+ IStatus status = copyFile(in, file.getPath()); >+ if (!status.isOK()) { >+ MultiStatus status2 = new MultiStatus(JavaServerPlugin.PLUGIN_ID, 0, NLS.bind(Messages.errorDelete, file.toString()), null); >+ status2.add(status); >+ throw new CoreException(status2); >+ } >+ tempFile.delete(); >+ return; >+ } catch (FileNotFoundException e) { >+ // Shouldn't occur. >+ } >+ } > tempFile.delete(); > throw new CoreException(new Status(IStatus.ERROR, JavaServerPlugin.PLUGIN_ID, 0, NLS.bind(Messages.errorDelete, file.toString()), null)); > } >@@ -669,9 +758,9 @@ > * @param f > * @return <code>true</code> if it succeeds, <code>false</code> otherwise > */ >- private static boolean safeDelete(File f) { >+ private static boolean safeDelete(File f, int retrys) { > int count = 0; >- while (count < 10) { >+ while (count < retrys) { > if (!f.exists()) > return true; > >@@ -680,12 +769,15 @@ > if (!f.exists()) > return true; > >- try { >- Thread.sleep(100); >- } catch (Exception e) { >- // ignore >- } > count++; >+ // delay if we are going to try again >+ if (count < retrys) { >+ try { >+ Thread.sleep(100); >+ } catch (Exception e) { >+ // ignore >+ } >+ } > } > return false; > } >#P org.eclipse.jst.server.tomcat.core >Index: tomcatcore/org/eclipse/jst/server/tomcat/core/internal/TomcatServerBehaviour.java >=================================================================== >RCS file: /cvsroot/webtools/jst/components/server/plugins/org.eclipse.jst.server.tomcat.core/tomcatcore/org/eclipse/jst/server/tomcat/core/internal/TomcatServerBehaviour.java,v >retrieving revision 1.61 >diff -u -r1.61 TomcatServerBehaviour.java >--- tomcatcore/org/eclipse/jst/server/tomcat/core/internal/TomcatServerBehaviour.java 26 Jul 2006 15:29:23 -0000 1.61 >+++ tomcatcore/org/eclipse/jst/server/tomcat/core/internal/TomcatServerBehaviour.java 28 Jul 2006 12:51:16 -0000 >@@ -286,7 +286,7 @@ > } else { > IPath to = getServer().getRuntime().getLocation().append("webapps").append(module[0].getName()); > IModuleResource[] mr = getResources(module); >- IStatus[] stat = PublishUtil.publishSmart(mr, to, monitor); >+ IStatus[] stat = PublishUtil.publishSmart(mr, to, true, monitor); > PublishOperation2.addArrayToList(status, stat); > p.put(module[0].getId(), to.toOSString()); > } >@@ -327,7 +327,7 @@ > } > > IModuleResource[] mr = getResources(module); >- IStatus[] stat = PublishUtil.publishZip(mr, jarPath, monitor); >+ IStatus[] stat = PublishUtil.publishZip(mr, jarPath, true, monitor); > List status = new ArrayList(); > PublishOperation2.addArrayToList(status, stat); > PublishOperation2.throwException(status); >Index: tomcatcore/org/eclipse/jst/server/tomcat/core/internal/PublishOperation2.java >=================================================================== >RCS file: /cvsroot/webtools/jst/components/server/plugins/org.eclipse.jst.server.tomcat.core/tomcatcore/org/eclipse/jst/server/tomcat/core/internal/PublishOperation2.java,v >retrieving revision 1.15 >diff -u -r1.15 PublishOperation2.java >--- tomcatcore/org/eclipse/jst/server/tomcat/core/internal/PublishOperation2.java 26 Jul 2006 15:31:36 -0000 1.15 >+++ tomcatcore/org/eclipse/jst/server/tomcat/core/internal/PublishOperation2.java 28 Jul 2006 12:51:15 -0000 >@@ -68,7 +68,7 @@ > > if (kind == IServer.PUBLISH_CLEAN || kind == IServer.PUBLISH_FULL) { > IModuleResource[] mr = server.getResources(module); >- IStatus[] stat = PublishUtil.publishFull(mr, path, monitor); >+ IStatus[] stat = PublishUtil.publishFull(mr, path, true, monitor); > addArrayToList(status, stat); > return; > } >@@ -77,7 +77,7 @@ > > int size = delta.length; > for (int i = 0; i < size; i++) { >- IStatus[] stat = PublishUtil.publishDelta(delta[i], path, monitor); >+ IStatus[] stat = PublishUtil.publishDelta(delta[i], path, true, monitor); > addArrayToList(status, stat); > } > } >@@ -106,7 +106,7 @@ > path.toFile().mkdirs(); > > IModuleResource[] mr = server.getResources(module); >- IStatus[] stat = PublishUtil.publishZip(mr, jarPath, monitor); >+ IStatus[] stat = PublishUtil.publishZip(mr, jarPath, true, monitor); > addArrayToList(status, stat); > } >
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 125524
: 47122