diff options
Diffstat (limited to 'bundles/org.eclipse.equinox.p2.artifact.repository')
3 files changed, 29 insertions, 4 deletions
diff --git a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/Activator.java b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/Activator.java index cf9a88288..35006dcce 100644 --- a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/Activator.java +++ b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/Activator.java @@ -22,7 +22,9 @@ import org.osgi.framework.BundleActivator; import org.osgi.framework.BundleContext; public class Activator implements BundleActivator { + public static final String ID = "org.eclipse.equinox.p2.artifact.repository"; //$NON-NLS-1$ + public static final String ENABLE_ARTIFACT_LOCKING = "eclipse.p2.internal.simple.artifact.repository.locking"; //$NON-NLS-1$ public static final String REPO_PROVIDER_XPT = ID + '.' + "artifactRepositories"; //$NON-NLS-1$ private Map<URI, Location> locationCache = null; @@ -50,6 +52,16 @@ public class Activator implements BundleActivator { return Activator.instance; } + public boolean enableArtifactLocking() { + String property = getContext().getProperty(ENABLE_ARTIFACT_LOCKING); + if (property == null || property.length() == 0) + return true; // return true by default; + Boolean valueOf = Boolean.valueOf(property); + if (valueOf != null) + return valueOf.booleanValue(); + return true; + } + /** * Returns the lock location for a given artifact repository * @param repositoryLocation A URI pointing to an artifact repository. Currently only @@ -63,7 +75,7 @@ public class Activator implements BundleActivator { } Location anyLoc = (Location) ServiceHelper.getService(Activator.getContext(), Location.class.getName()); File repositoryFile = URIUtil.toFile(repositoryLocation); - Location location = anyLoc.createLocation(null, getLockFile(repositoryLocation).toURL(), isReadOnly(repositoryFile)); + Location location = anyLoc.createLocation(null, getLockFile(repositoryLocation).toURL(), isReadOnly(repositoryFile)); location.set(getLockFile(repositoryLocation).toURL(), false); locationCache.put(repositoryLocation, location); return location; @@ -75,11 +87,11 @@ public class Activator implements BundleActivator { */ private boolean isReadOnly(File file) { if (file == null) - return true; // If we've reached the root, then return true + return true; // If we've reached the root, then return true else if (file.canWrite()) - return false; // If we can write to this area, then it's not read-only + return false; // If we can write to this area, then it's not read-only else if (file.exists()) - return true; // if we can't write && file exists, then this is a read only area + return true; // if we can't write && file exists, then this is a read only area else return isReadOnly(file.getParentFile()); } 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 7a71e8b23..469e1255b 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 @@ -1341,6 +1341,9 @@ public class SimpleArtifactRepository extends AbstractArtifactRepository impleme * load it, see {@link SimpleArtifactRepository#lockAndLoad(boolean, IProgressMonitor)}. */ private synchronized boolean lock(boolean wait, IProgressMonitor monitor) throws IOException { + if (!Activator.getInstance().enableArtifactLocking()) + return true; + if (holdsLock()) { throw new IllegalStateException("Locking is not reentrant"); //$NON-NLS-1$ } @@ -1474,6 +1477,10 @@ public class SimpleArtifactRepository extends AbstractArtifactRepository impleme } private void unlock() { + if (!Activator.getInstance().enableArtifactLocking()) { + holdsLock = false; + return; + } if (lockLocation != null) { // If we don't have the lock location, then we don't have the lock holdsLock = false; diff --git a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/simple/SimpleArtifactRepositoryIO.java b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/simple/SimpleArtifactRepositoryIO.java index bbb92f57a..12e41b06c 100644 --- a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/simple/SimpleArtifactRepositoryIO.java +++ b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/simple/SimpleArtifactRepositoryIO.java @@ -142,6 +142,9 @@ public class SimpleArtifactRepositoryIO { } private synchronized boolean lock(URI repositoryLocation, boolean wait, IProgressMonitor monitor) throws IOException { + if (!Activator.getInstance().enableArtifactLocking()) + return true; // Don't use locking + lockLocation = getLockLocation(repositoryLocation); boolean locked = lockLocation.lock(); if (locked || !wait) @@ -162,6 +165,9 @@ public class SimpleArtifactRepositoryIO { } private void unlock(URI repositoryLocation) { + if (!Activator.getInstance().enableArtifactLocking()) + return; + if (lockLocation != null) { lockLocation.release(); } |