use of org.apache.archiva.repository.storage.RepositoryStorage in project archiva by apache.
the class AbstractStorageUtilTest method testDeleteWithExceptionFailFast.
@Test
void testDeleteWithExceptionFailFast() {
StorageAsset root = createTree();
RepositoryStorage storage = createStorage(root);
activateException(root);
StorageUtil.deleteRecursively(root, true);
int expected = 113;
testDeletionStatus(expected, storage);
}
use of org.apache.archiva.repository.storage.RepositoryStorage in project archiva by apache.
the class StorageUtil method deleteRecursively.
/**
* Deletes the given asset and all child assets recursively.
* IOExceptions during deletion are ignored.
*
* @param baseDir The base asset to remove.
*/
public static final void deleteRecursively(StorageAsset baseDir) {
RepositoryStorage storage = baseDir.getStorage();
walk(baseDir, a -> {
try {
storage.removeAsset(a);
} catch (IOException e) {
LOG.error("Could not delete asset {}: {}", a.getPath(), e.getMessage(), e);
}
});
}
use of org.apache.archiva.repository.storage.RepositoryStorage 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