use of org.apache.archiva.repository.storage.RepositoryStorage in project archiva by apache.
the class StorageUtil method moveAsset.
/**
* Moves a asset between different storage instances.
* If you know that source and asset are from the same storage instance, the move method of the storage
* instance may be faster.
*
* @param source The source asset
* @param target The target asset
* @param locked If true, a lock is used for the move operation.
* @param copyOptions Options for copying
* @throws IOException If the move fails
*/
public static final void moveAsset(StorageAsset source, StorageAsset target, boolean locked, CopyOption... copyOptions) throws IOException {
if (source.isFileBased() && target.isFileBased()) {
// Move is atomic operation
if (!Files.exists(target.getFilePath().getParent())) {
Files.createDirectories(target.getFilePath().getParent());
}
Files.move(source.getFilePath(), target.getFilePath(), copyOptions);
} else {
try {
final RepositoryStorage sourceStorage = source.getStorage();
final RepositoryStorage targetStorage = target.getStorage();
sourceStorage.consumeDataFromChannel(source, is -> wrapWriteFunction(is, targetStorage, target, locked), locked);
sourceStorage.removeAsset(source);
} catch (IOException e) {
throw e;
} catch (Throwable e) {
Throwable cause = e.getCause();
if (cause instanceof IOException) {
throw (IOException) cause;
} else {
throw new IOException(e);
}
}
}
}
use of org.apache.archiva.repository.storage.RepositoryStorage in project archiva by apache.
the class AbstractStorageUtilTest method testCopyRecursive.
@Test
void testCopyRecursive() throws IOException {
StorageAsset root = createTree();
createStorage(root);
StorageAsset destinationRoot = createRootAsset();
RepositoryStorage destinationStorage = createStorage(destinationRoot);
StorageAsset destination = destinationStorage.getAsset("");
boolean result = StorageUtil.copyRecursively(root, destination, false);
Assertions.assertTrue(result);
Assertions.assertTrue(destination.exists());
Assertions.assertTrue(destination.resolve("000/000000/000000000").exists());
Assertions.assertTrue(destination.resolve("011/011000/011000000").exists());
Assertions.assertTrue(destination.resolve("010/010000/010000000").exists());
Assertions.assertTrue(destination.resolve("000/000000/000000000").exists());
}
use of org.apache.archiva.repository.storage.RepositoryStorage in project archiva by apache.
the class AbstractStorageUtilTest method testDelete.
@Test
void testDelete() {
StorageAsset root = createTree();
RepositoryStorage storage = createStorage(root);
StorageUtil.deleteRecursively(root);
int expected = LEVEL1 * LEVEL2 * LEVEL3 + LEVEL1 * LEVEL2 + LEVEL1 + 1;
testDeletionStatus(expected, storage);
}
use of org.apache.archiva.repository.storage.RepositoryStorage in project archiva by apache.
the class MavenIndexManager method getIndexPath.
private StorageAsset getIndexPath(URI indexDirUri, RepositoryStorage repoStorage, String defaultDir) throws IOException {
StorageAsset rootAsset = repoStorage.getRoot();
RepositoryStorage storage = rootAsset.getStorage();
Path indexDirectory;
Path repositoryPath = rootAsset.getFilePath().toAbsolutePath();
StorageAsset indexDir;
if (!StringUtils.isEmpty(indexDirUri.toString())) {
indexDirectory = PathUtil.getPathFromUri(indexDirUri);
// not absolute so create it in repository directory
if (indexDirectory.isAbsolute() && !indexDirectory.startsWith(repositoryPath)) {
if (storage instanceof FilesystemStorage) {
FilesystemStorage fsStorage = (FilesystemStorage) storage;
FilesystemStorage indexStorage = new FilesystemStorage(indexDirectory.getParent(), fsStorage.getFileLockManager());
indexDir = indexStorage.getAsset(indexDirectory.getFileName().toString());
} else {
throw new IOException("The given storage is not file based.");
}
} else if (indexDirectory.isAbsolute()) {
indexDir = storage.getAsset(repositoryPath.relativize(indexDirectory).toString());
} else {
indexDir = storage.getAsset(indexDirectory.toString());
}
} else {
indexDir = storage.getAsset(defaultDir);
}
if (!indexDir.exists()) {
indexDir.create(AssetType.CONTAINER);
}
return indexDir;
}
use of org.apache.archiva.repository.storage.RepositoryStorage in project archiva by apache.
the class AbstractStorageUtilTest method testDeleteWithException.
@Test
void testDeleteWithException() {
StorageAsset root = createTree();
RepositoryStorage storage = createStorage(root);
activateException(root);
StorageUtil.deleteRecursively(root);
int expected = LEVEL1 * LEVEL2 * LEVEL3 + LEVEL1 * LEVEL2 + LEVEL1 + 1;
testDeletionStatus(expected, storage);
}
Aggregations