use of java.nio.file.AtomicMoveNotSupportedException in project buck by facebook.
the class Main method moveToTrash.
private static void moveToTrash(ProjectFilesystem filesystem, Console console, BuildId buildId, Path... pathsToMove) throws IOException {
Path trashPath = filesystem.getBuckPaths().getTrashDir().resolve(buildId.toString());
filesystem.mkdirs(trashPath);
for (Path pathToMove : pathsToMove) {
try {
// Technically this might throw AtomicMoveNotSupportedException,
// but we're moving a path within buck-out, so we don't expect this
// to throw.
//
// If it does throw, we'll complain loudly and synchronously delete
// the file instead.
filesystem.move(pathToMove, trashPath.resolve(pathToMove.getFileName()), StandardCopyOption.ATOMIC_MOVE);
} catch (NoSuchFileException e) {
LOG.verbose(e, "Ignoring missing path %s", pathToMove);
} catch (AtomicMoveNotSupportedException e) {
console.getStdErr().format("Atomic moves not supported, falling back to synchronous delete: %s", e);
MoreFiles.deleteRecursivelyIfExists(pathToMove);
}
}
}
use of java.nio.file.AtomicMoveNotSupportedException in project elasticsearch by elastic.
the class ExceptionSerializationTests method testFileSystemExceptions.
public void testFileSystemExceptions() throws IOException {
for (FileSystemException ex : Arrays.asList(new FileSystemException("a", "b", "c"), new NoSuchFileException("a", "b", "c"), new NotDirectoryException("a"), new DirectoryNotEmptyException("a"), new AtomicMoveNotSupportedException("a", "b", "c"), new FileAlreadyExistsException("a", "b", "c"), new AccessDeniedException("a", "b", "c"), new FileSystemLoopException("a"))) {
FileSystemException serialize = serialize(ex);
assertEquals(serialize.getClass(), ex.getClass());
assertEquals("a", serialize.getFile());
if (serialize.getClass() == NotDirectoryException.class || serialize.getClass() == FileSystemLoopException.class || serialize.getClass() == DirectoryNotEmptyException.class) {
assertNull(serialize.getOtherFile());
assertNull(serialize.getReason());
} else {
assertEquals(serialize.getClass().toString(), "b", serialize.getOtherFile());
assertEquals(serialize.getClass().toString(), "c", serialize.getReason());
}
}
}
use of java.nio.file.AtomicMoveNotSupportedException in project google-cloud-java by GoogleCloudPlatform.
the class CloudStorageFileSystemProvider method move.
@Override
public void move(Path source, Path target, CopyOption... options) throws IOException {
initStorage();
for (CopyOption option : options) {
if (option == StandardCopyOption.ATOMIC_MOVE) {
throw new AtomicMoveNotSupportedException(source.toString(), target.toString(), "Google Cloud Storage does not support atomic move operations.");
}
}
copy(source, target, options);
delete(source);
}
use of java.nio.file.AtomicMoveNotSupportedException in project Terasology by MovingBlocks.
the class SaveTransaction method renameMergeFolder.
private void renameMergeFolder() throws IOException {
Path directoryForUnfinishedFiles = storagePathProvider.getUnfinishedSaveTransactionPath();
Path directoryForFinishedFiles = storagePathProvider.getUnmergedChangesPath();
try {
Files.move(directoryForUnfinishedFiles, directoryForFinishedFiles, StandardCopyOption.ATOMIC_MOVE);
} catch (AtomicMoveNotSupportedException e) {
logger.warn("Atomic rename of merge folder was not possible, doing it non atomically...");
Files.move(directoryForUnfinishedFiles, directoryForFinishedFiles);
}
}
use of java.nio.file.AtomicMoveNotSupportedException in project Terasology by MovingBlocks.
the class SaveTransactionHelper method mergeChanges.
/**
* Merges all outstanding changes into the save game. If this operation gets interrupted it can be started again
* without any file corruption when the file system supports atomic moves.
* <br><br>
* The write lock for the save directory should be acquired before this method gets called.
*/
public void mergeChanges() throws IOException {
final Path sourceDirectory = storagePathProvider.getUnmergedChangesPath();
final Path targetDirectory = storagePathProvider.getStoragePathDirectory();
Files.walkFileTree(sourceDirectory, new SimpleFileVisitor<Path>() {
boolean atomicNotPossibleLogged;
@Override
public FileVisitResult preVisitDirectory(Path sourceSubDir, BasicFileAttributes attrs) throws IOException {
Path targetSubDir = targetDirectory.resolve(sourceDirectory.relativize(sourceSubDir));
if (!Files.isDirectory(targetSubDir)) {
Files.createDirectory(targetSubDir);
}
return FileVisitResult.CONTINUE;
}
@Override
public FileVisitResult visitFile(Path sourcePath, BasicFileAttributes attrs) throws IOException {
Path targetPath = targetDirectory.resolve(sourceDirectory.relativize(sourcePath));
try {
// Delete file, as behavior of atomic move is undefined if target file exists:
Files.deleteIfExists(targetPath);
Files.move(sourcePath, targetPath, StandardCopyOption.ATOMIC_MOVE);
} catch (AtomicMoveNotSupportedException e) {
if (!atomicNotPossibleLogged) {
logger.warn("Atomic move was not possible, doing it non atomically...");
atomicNotPossibleLogged = true;
}
Files.move(sourcePath, targetPath);
}
return FileVisitResult.CONTINUE;
}
@Override
public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException {
try {
Files.delete(dir);
} catch (DirectoryNotEmptyException e) {
/**
* Happens rarely for some players on windows (See issue #2160). Exact reason for this behavior is
* unknown. Maybe they have some kind of background task that processes that creates a temporary
* files in new directories to store some intermediate scan result.
*/
logger.warn("The save job could not cleanup a temporarly created directory, it will retry once in one second");
try {
Thread.sleep(1000L);
} catch (InterruptedException e1) {
// Reset flag and ignore it
Thread.currentThread().interrupt();
}
Files.delete(dir);
}
return FileVisitResult.CONTINUE;
}
});
}
Aggregations