use of org.apache.archiva.common.filelock.FileLockManager in project archiva by apache.
the class BasicManagedRepository method newFilesystemInstance.
/**
* Creates a filesystem based repository instance. The path is built by basePath/repository-id
*
* @param id The repository id
* @param name The name of the repository
* @param repositoryPath The path to the repository
* @return The repository instance
* @throws IOException
*/
public static BasicManagedRepository newFilesystemInstance(String id, String name, Path repositoryPath) throws IOException {
FileLockManager lockManager = new DefaultFileLockManager();
FilesystemStorage storage = new FilesystemStorage(repositoryPath, lockManager);
return new BasicManagedRepository(id, name, storage);
}
use of org.apache.archiva.common.filelock.FileLockManager in project archiva by apache.
the class BasicRemoteRepository method newFilesystemInstance.
public static BasicRemoteRepository newFilesystemInstance(String id, String name, Path basePath) throws IOException {
FileLockManager lockManager = new DefaultFileLockManager();
FilesystemStorage storage = new FilesystemStorage(basePath.resolve(id), lockManager);
return new BasicRemoteRepository(id, name, storage);
}
use of org.apache.archiva.common.filelock.FileLockManager in project archiva by apache.
the class BasicManagedRepositoryValidatorTest method createRepository.
protected EditableManagedRepository createRepository(String id, String name, Path location) throws IOException {
FileLockManager lockManager = new DefaultFileLockManager();
FilesystemStorage storage = new FilesystemStorage(location.toAbsolutePath(), lockManager);
BasicManagedRepository repo = new BasicManagedRepository(id, name, storage);
repo.setLocation(location.toAbsolutePath().toUri());
repo.setContent(new ManagedRepositoryContentMock());
return repo;
}
use of org.apache.archiva.common.filelock.FileLockManager in project archiva by apache.
the class BasicRemoteRepositoryValidatorTest method createRepository.
protected EditableRemoteRepository createRepository(String id, String name, Path location) throws IOException {
FileLockManager lockManager = new DefaultFileLockManager();
FilesystemStorage storage = new FilesystemStorage(location.toAbsolutePath(), lockManager);
BasicRemoteRepository repo = new BasicRemoteRepository(id, name, storage);
repo.setLocation(location.toAbsolutePath().toUri());
repo.setContent(new RemoteRepositoryContentMock());
return repo;
}
use of org.apache.archiva.common.filelock.FileLockManager in project archiva by apache.
the class FsStorageUtil method copyAsset.
/**
* Copies the source asset to the target. The assets may be from different RepositoryStorage instances.
* If you know that source and asset are from the same storage instance, the copy method of the storage
* instance may be faster.
*
* @param source The source asset
* @param target The target asset
* @param locked If true, a readlock is set on the source and a write lock is set on the target.
* @param copyOptions Copy options
* @throws IOException
*/
public static final void copyAsset(final StorageAsset source, final StorageAsset target, boolean locked, final CopyOption... copyOptions) throws IOException {
if (source.isFileBased() && target.isFileBased()) {
// Short cut for FS operations
final Path sourcePath = source.getFilePath();
final Path targetPath = target.getFilePath();
if (locked) {
final FileLockManager lmSource = ((FilesystemStorage) source.getStorage()).getFileLockManager();
final FileLockManager lmTarget = ((FilesystemStorage) target.getStorage()).getFileLockManager();
Lock lockRead = null;
Lock lockWrite = null;
try {
lockRead = lmSource.readFileLock(sourcePath);
} catch (Exception e) {
log.error("Could not create read lock on {}", sourcePath);
throw new IOException(e);
}
try {
lockWrite = lmTarget.writeFileLock(targetPath);
} catch (Exception e) {
log.error("Could not create write lock on {}", targetPath);
throw new IOException(e);
}
try {
Files.copy(sourcePath, targetPath, copyOptions);
} finally {
if (lockRead != null) {
try {
lmSource.release(lockRead);
} catch (FileLockException e) {
log.error("Error during lock release of read lock {}", lockRead.getFile());
}
}
if (lockWrite != null) {
try {
lmTarget.release(lockWrite);
} catch (FileLockException e) {
log.error("Error during lock release of write lock {}", lockWrite.getFile());
}
}
}
} else {
Files.copy(sourcePath, targetPath, copyOptions);
}
} else {
try {
final RepositoryStorage sourceStorage = source.getStorage();
final RepositoryStorage targetStorage = target.getStorage();
sourceStorage.consumeDataFromChannel(source, is -> wrapWriteFunction(is, targetStorage, target, locked), locked);
} catch (IOException e) {
throw e;
} catch (Throwable e) {
Throwable cause = e.getCause();
if (cause instanceof IOException) {
throw (IOException) cause;
} else {
throw new IOException(e);
}
}
}
}
Aggregations