use of org.opencastproject.assetmanager.impl.storage.AssetStoreException in project opencast by opencast.
the class AbstractFileSystemAssetStore method findStoragePathFile.
/**
* Returns a file {@link Option} from a storage path if one is found or an empty {@link Option}
*
* @param storagePath
* the storage path
* @return the file {@link Option}
*/
private Opt<File> findStoragePathFile(final StoragePath storagePath) {
final FilenameFilter filter = new FilenameFilter() {
@Override
public boolean accept(File dir, String name) {
return FilenameUtils.getBaseName(name).equals(storagePath.getMediaPackageElementId());
}
};
final File containerDir = createFile(storagePath, Opt.none(String.class)).getParentFile();
return nul(containerDir.listFiles(filter)).bind(new Fn<File[], Opt<File>>() {
@Override
public Opt<File> apply(File[] files) {
switch(files.length) {
case 0:
return none();
case 1:
return some(files[0]);
default:
throw new AssetStoreException("Storage path " + files[0].getParent() + "contains multiple files with the same element id!: " + storagePath.getMediaPackageElementId());
}
}
});
}
use of org.opencastproject.assetmanager.impl.storage.AssetStoreException in project opencast by opencast.
the class AbstractFileSystemAssetStore method copy.
@Override
public boolean copy(final StoragePath from, final StoragePath to) throws AssetStoreException {
return findStoragePathFile(from).map(new Fn<File, Boolean>() {
@Override
public Boolean apply(File f) {
final File t = createFile(to, f);
mkParent(t);
logger.debug("Copying {} to {}", f.getAbsolutePath(), t.getAbsolutePath());
try {
link(f, t, true);
} catch (IOException e) {
logger.error("Error copying archive file {} to {}", f, t);
throw new AssetStoreException(e);
}
return true;
}
}).getOr(false);
}
use of org.opencastproject.assetmanager.impl.storage.AssetStoreException in project opencast by opencast.
the class AbstractFileSystemAssetStore method delete.
@Override
public boolean delete(DeletionSelector sel) throws AssetStoreException {
File dir = getDeletionSelectorDir(sel);
try {
FileUtils.deleteDirectory(dir);
// also delete the media package directory if all versions have been deleted
FileSupport.deleteHierarchyIfEmpty(file(path(getRootDirectory(), sel.getOrganizationId())), dir.getParentFile());
return true;
} catch (IOException e) {
logger.error("Error deleting directory from archive {}", dir);
throw new AssetStoreException(e);
}
}
use of org.opencastproject.assetmanager.impl.storage.AssetStoreException in project opencast by opencast.
the class AbstractFileSystemAssetStore method put.
@Override
public void put(StoragePath storagePath, Source source) throws AssetStoreException {
// Retrieving the file from the workspace has the advantage that in most cases the file already exists in the local
// working file repository. In the very few cases where the file is not in the working file repository,
// this strategy leads to a minor overhead because the file not only gets downloaded and stored in the file system
// but also a hard link needs to be created (or if that's not possible, a copy of the file.
final File origin = getUniqueFileFromWorkspace(source);
final File destination = createFile(storagePath, source);
try {
mkParent(destination);
link(origin, destination);
} catch (IOException e) {
logger.error("Error while linking/copying file {} to {}: {}", origin, destination, getMessage(e));
throw new AssetStoreException(e);
} finally {
if (origin != null) {
FileUtils.deleteQuietly(origin);
}
}
}
Aggregations