Search in sources :

Example 11 with FileLockManager

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);
}
Also used : FileLockManager(org.apache.archiva.common.filelock.FileLockManager) DefaultFileLockManager(org.apache.archiva.common.filelock.DefaultFileLockManager) FilesystemStorage(org.apache.archiva.repository.storage.fs.FilesystemStorage) DefaultFileLockManager(org.apache.archiva.common.filelock.DefaultFileLockManager)

Example 12 with FileLockManager

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);
}
Also used : FileLockManager(org.apache.archiva.common.filelock.FileLockManager) DefaultFileLockManager(org.apache.archiva.common.filelock.DefaultFileLockManager) FilesystemStorage(org.apache.archiva.repository.storage.fs.FilesystemStorage) DefaultFileLockManager(org.apache.archiva.common.filelock.DefaultFileLockManager)

Example 13 with FileLockManager

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;
}
Also used : FileLockManager(org.apache.archiva.common.filelock.FileLockManager) DefaultFileLockManager(org.apache.archiva.common.filelock.DefaultFileLockManager) FilesystemStorage(org.apache.archiva.repository.storage.fs.FilesystemStorage) DefaultFileLockManager(org.apache.archiva.common.filelock.DefaultFileLockManager) ManagedRepositoryContentMock(org.apache.archiva.repository.mock.ManagedRepositoryContentMock)

Example 14 with FileLockManager

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;
}
Also used : FileLockManager(org.apache.archiva.common.filelock.FileLockManager) DefaultFileLockManager(org.apache.archiva.common.filelock.DefaultFileLockManager) RemoteRepositoryContentMock(org.apache.archiva.repository.mock.RemoteRepositoryContentMock) FilesystemStorage(org.apache.archiva.repository.storage.fs.FilesystemStorage) DefaultFileLockManager(org.apache.archiva.common.filelock.DefaultFileLockManager)

Example 15 with FileLockManager

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);
            }
        }
    }
}
Also used : FileLockManager(org.apache.archiva.common.filelock.FileLockManager) RepositoryStorage(org.apache.archiva.repository.storage.RepositoryStorage) FileLockException(org.apache.archiva.common.filelock.FileLockException) IOException(java.io.IOException) IOException(java.io.IOException) FileLockException(org.apache.archiva.common.filelock.FileLockException) Lock(org.apache.archiva.common.filelock.Lock)

Aggregations

FileLockManager (org.apache.archiva.common.filelock.FileLockManager)15 DefaultFileLockManager (org.apache.archiva.common.filelock.DefaultFileLockManager)14 FilesystemStorage (org.apache.archiva.repository.storage.fs.FilesystemStorage)14 Path (java.nio.file.Path)2 BasicManagedRepository (org.apache.archiva.repository.base.managed.BasicManagedRepository)2 IOException (java.io.IOException)1 FileLockException (org.apache.archiva.common.filelock.FileLockException)1 Lock (org.apache.archiva.common.filelock.Lock)1 BasicRemoteRepository (org.apache.archiva.repository.base.remote.BasicRemoteRepository)1 ManagedRepositoryContentMock (org.apache.archiva.repository.mock.ManagedRepositoryContentMock)1 RemoteRepositoryContentMock (org.apache.archiva.repository.mock.RemoteRepositoryContentMock)1 ManagedRepositoryContentMock (org.apache.archiva.repository.scanner.mock.ManagedRepositoryContentMock)1 RepositoryStorage (org.apache.archiva.repository.storage.RepositoryStorage)1