diff options
author | Andrew Niefer | 2009-02-20 16:52:46 +0000 |
---|---|---|
committer | Andrew Niefer | 2009-02-20 16:52:46 +0000 |
commit | 0d0df278c184ad6888f3da8bac84ba02d3cde6bb (patch) | |
tree | b2310e23acceb03a48d59abcf0e366be722ecb50 /bundles/org.eclipse.equinox.p2.artifact.repository | |
parent | 4e2e15556d9e0f06e42c5fb42b82942199ced72a (diff) | |
download | rt.equinox.p2-0d0df278c184ad6888f3da8bac84ba02d3cde6bb.tar.gz rt.equinox.p2-0d0df278c184ad6888f3da8bac84ba02d3cde6bb.tar.xz rt.equinox.p2-0d0df278c184ad6888f3da8bac84ba02d3cde6bb.zip |
bug 265654 - race condition in mkdirs
Diffstat (limited to 'bundles/org.eclipse.equinox.p2.artifact.repository')
-rw-r--r-- | bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/simple/SimpleArtifactRepository.java | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/simple/SimpleArtifactRepository.java b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/simple/SimpleArtifactRepository.java index f06795d04..726ddc1fb 100644 --- a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/simple/SimpleArtifactRepository.java +++ b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/simple/SimpleArtifactRepository.java @@ -709,7 +709,7 @@ public class SimpleArtifactRepository extends AbstractArtifactRepository impleme OutputStream target = null; try { if (isFolderBased(newDescriptor)) { - outputFile.mkdirs(); + mkdirs(outputFile); if (!outputFile.isDirectory()) throw failedWrite(new IOException(NLS.bind(Messages.sar_failedMkdir, outputFile.toString()))); target = new ZippedFolderOutputStream(outputFile); @@ -731,6 +731,20 @@ public class SimpleArtifactRepository extends AbstractArtifactRepository impleme } + /** + * We implement mkdirs ourselves because this code is known to run in + * highly concurrent scenarios, and there is a race condition in the JRE implementation + * of mkdirs (see bug 265654). + */ + private void mkdirs(File dir) { + if (dir.exists()) + return; + if (dir.mkdir()) + return; + mkdirs(dir.getParentFile()); + dir.mkdir(); + } + private ProvisionException failedWrite(Exception e) throws ProvisionException { String msg = NLS.bind(Messages.repoFailedWrite, getLocation()); throw new ProvisionException(new Status(IStatus.ERROR, Activator.ID, ProvisionException.REPOSITORY_FAILED_WRITE, msg, e)); @@ -856,7 +870,7 @@ public class SimpleArtifactRepository extends AbstractArtifactRepository impleme } if (!artifactsFile.exists()) { // create parent folders - artifactsFile.getParentFile().mkdirs(); + mkdirs(artifactsFile.getParentFile()); } os = new FileOutputStream(artifactsFile); } else { @@ -864,8 +878,7 @@ public class SimpleArtifactRepository extends AbstractArtifactRepository impleme artifactsFile.delete(); } if (!jarFile.exists()) { - if (!jarFile.getParentFile().exists()) - jarFile.getParentFile().mkdirs(); + mkdirs(jarFile.getParentFile()); jarFile.createNewFile(); } JarOutputStream jOs = new JarOutputStream(new FileOutputStream(jarFile)); |