Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohn Arthorne2008-02-28 17:08:52 +0000
committerJohn Arthorne2008-02-28 17:08:52 +0000
commit7e43d76151884d668d1f655cc4f0bccbea22348a (patch)
treef9c68957931a1f6005f21aaa64670f31da0222d2
parent3235d6525c3aa664dfc27b04f46821f5deee9571 (diff)
downloadrt.equinox.p2-7e43d76151884d668d1f655cc4f0bccbea22348a.tar.gz
rt.equinox.p2-7e43d76151884d668d1f655cc4f0bccbea22348a.tar.xz
rt.equinox.p2-7e43d76151884d668d1f655cc4f0bccbea22348a.zip
Bug 216047 [prov] Repositories reading from a local repo create a temporary copy of the index file
-rw-r--r--bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/provisional/spi/p2/artifact/repository/SimpleArtifactRepositoryFactory.java47
1 files changed, 29 insertions, 18 deletions
diff --git a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/provisional/spi/p2/artifact/repository/SimpleArtifactRepositoryFactory.java b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/provisional/spi/p2/artifact/repository/SimpleArtifactRepositoryFactory.java
index ca4279e53..b5b22854a 100644
--- a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/provisional/spi/p2/artifact/repository/SimpleArtifactRepositoryFactory.java
+++ b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/provisional/spi/p2/artifact/repository/SimpleArtifactRepositoryFactory.java
@@ -26,37 +26,48 @@ import org.eclipse.osgi.util.NLS;
public class SimpleArtifactRepositoryFactory implements IArtifactRepositoryFactory {
public IArtifactRepository load(URL location, IProgressMonitor monitor) throws ProvisionException {
+ final String PROTOCOL_FILE = "file"; //$NON-NLS-1$
long time = 0;
final String debugMsg = "Restoring artifact repository "; //$NON-NLS-1$
if (Tracing.DEBUG_METADATA_PARSING) {
Tracing.debug(debugMsg + location);
time = -System.currentTimeMillis();
}
- File temp = null;
+ File localFile = null;
+ boolean local = false;
try {
SubMonitor sub = SubMonitor.convert(monitor, 300);
- // TODO This temporary file stuff is not very elegant.
OutputStream artifacts = null;
- temp = File.createTempFile("artifacts", ".xml"); //$NON-NLS-1$ //$NON-NLS-2$
// try with compressed
boolean compress = true;
- try {
- artifacts = new BufferedOutputStream(new FileOutputStream(temp));
- IStatus status = getTransport().download(SimpleArtifactRepository.getActualLocation(location, compress).toExternalForm(), artifacts, sub.newChild(100));
- if (!status.isOK()) {
- // retry uncompressed
+ if (PROTOCOL_FILE.equals(location.getProtocol())) {
+ local = true;
+ localFile = new File(SimpleArtifactRepository.getActualLocation(location, true).getPath());
+ if (!localFile.exists()) {
+ localFile = new File(SimpleArtifactRepository.getActualLocation(location, false).getPath());
compress = false;
- status = getTransport().download(SimpleArtifactRepository.getActualLocation(location, compress).toExternalForm(), artifacts, sub.newChild(100));
- if (!status.isOK())
- throw new ProvisionException(new Status(IStatus.ERROR, Activator.ID, ProvisionException.REPOSITORY_NOT_FOUND, status.getMessage(), null));
}
- } finally {
- if (artifacts != null)
- artifacts.close();
+ } else {
+ //download to local temp file
+ localFile = File.createTempFile("artifacts", ".xml"); //$NON-NLS-1$ //$NON-NLS-2$
+ try {
+ artifacts = new BufferedOutputStream(new FileOutputStream(localFile));
+ IStatus status = getTransport().download(SimpleArtifactRepository.getActualLocation(location, compress).toExternalForm(), artifacts, sub.newChild(100));
+ if (!status.isOK()) {
+ // retry uncompressed
+ compress = false;
+ status = getTransport().download(SimpleArtifactRepository.getActualLocation(location, compress).toExternalForm(), artifacts, sub.newChild(100));
+ if (!status.isOK())
+ throw new ProvisionException(new Status(IStatus.ERROR, Activator.ID, ProvisionException.REPOSITORY_NOT_FOUND, status.getMessage(), null));
+ }
+ } finally {
+ if (artifacts != null)
+ artifacts.close();
+ }
}
InputStream descriptorStream = null;
try {
- descriptorStream = new BufferedInputStream(new FileInputStream(temp));
+ descriptorStream = new BufferedInputStream(new FileInputStream(localFile));
if (compress) {
URL actualFile = SimpleArtifactRepository.getActualLocation(location, false);
JarInputStream jInStream = new JarInputStream(descriptorStream);
@@ -71,7 +82,7 @@ public class SimpleArtifactRepositoryFactory implements IArtifactRepositoryFacto
descriptorStream = jInStream;
}
SimpleArtifactRepositoryIO io = new SimpleArtifactRepositoryIO();
- SimpleArtifactRepository result = (SimpleArtifactRepository) io.read(temp.toURL(), descriptorStream, sub.newChild(100));
+ SimpleArtifactRepository result = (SimpleArtifactRepository) io.read(localFile.toURL(), descriptorStream, sub.newChild(100));
result.initializeAfterLoad(location);
if (Tracing.DEBUG_METADATA_PARSING) {
time += System.currentTimeMillis();
@@ -89,8 +100,8 @@ public class SimpleArtifactRepositoryFactory implements IArtifactRepositoryFacto
String msg = NLS.bind(Messages.io_failedRead, location);
throw new ProvisionException(new Status(IStatus.ERROR, Activator.ID, ProvisionException.REPOSITORY_FAILED_READ, msg, e));
} finally {
- if (temp != null && !temp.delete())
- temp.deleteOnExit();
+ if (!local && localFile != null && !localFile.delete())
+ localFile.deleteOnExit();
}
}

Back to the top