8325302: Files.move(REPLACE_EXISTING) throws NoSuchFileException on deleted target
Reviewed-by: alanb
This commit is contained in:
parent
3a1f4d0f48
commit
299a8ee68d
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2008, 2023, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2008, 2024, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
@ -930,14 +930,16 @@ abstract class UnixFileSystem
|
|||||||
} catch (UnixException x) {
|
} catch (UnixException x) {
|
||||||
// target is non-empty directory that can't be replaced.
|
// target is non-empty directory that can't be replaced.
|
||||||
if (targetAttrs.isDirectory() &&
|
if (targetAttrs.isDirectory() &&
|
||||||
(x.errno() == EEXIST || x.errno() == ENOTEMPTY))
|
(x.errno() == EEXIST || x.errno() == ENOTEMPTY)) {
|
||||||
{
|
|
||||||
throw new DirectoryNotEmptyException(
|
throw new DirectoryNotEmptyException(
|
||||||
target.getPathForExceptionMessage());
|
target.getPathForExceptionMessage());
|
||||||
}
|
}
|
||||||
|
// ignore file not found otherwise rethrow
|
||||||
|
if (x.errno() != ENOENT) {
|
||||||
x.rethrowAsIOException(target);
|
x.rethrowAsIOException(target);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// first try rename
|
// first try rename
|
||||||
try {
|
try {
|
||||||
@ -1061,14 +1063,16 @@ abstract class UnixFileSystem
|
|||||||
} catch (UnixException x) {
|
} catch (UnixException x) {
|
||||||
// target is non-empty directory that can't be replaced.
|
// target is non-empty directory that can't be replaced.
|
||||||
if (targetAttrs.isDirectory() &&
|
if (targetAttrs.isDirectory() &&
|
||||||
(x.errno() == EEXIST || x.errno() == ENOTEMPTY))
|
(x.errno() == EEXIST || x.errno() == ENOTEMPTY)) {
|
||||||
{
|
|
||||||
throw new DirectoryNotEmptyException(
|
throw new DirectoryNotEmptyException(
|
||||||
target.getPathForExceptionMessage());
|
target.getPathForExceptionMessage());
|
||||||
}
|
}
|
||||||
|
// ignore file not found otherwise rethrow
|
||||||
|
if (x.errno() != ENOENT) {
|
||||||
x.rethrowAsIOException(target);
|
x.rethrowAsIOException(target);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// do the copy
|
// do the copy
|
||||||
if (sourceAttrs.isDirectory()) {
|
if (sourceAttrs.isDirectory()) {
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2008, 2023, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2008, 2024, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
@ -177,9 +177,13 @@ class WindowsFileCopy {
|
|||||||
target.getPathForExceptionMessage());
|
target.getPathForExceptionMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// ignore file not found otherwise rethrow
|
||||||
|
if (x.lastError() != ERROR_FILE_NOT_FOUND &&
|
||||||
|
x.lastError() != ERROR_PATH_NOT_FOUND) {
|
||||||
x.rethrowAsIOException(target);
|
x.rethrowAsIOException(target);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Use CopyFileEx if the file is not a directory or junction
|
// Use CopyFileEx if the file is not a directory or junction
|
||||||
if (!sourceAttrs.isDirectory() && !sourceAttrs.isDirectoryLink()) {
|
if (!sourceAttrs.isDirectory() && !sourceAttrs.isDirectoryLink()) {
|
||||||
@ -400,9 +404,13 @@ class WindowsFileCopy {
|
|||||||
target.getPathForExceptionMessage());
|
target.getPathForExceptionMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// ignore file not found otherwise rethrow
|
||||||
|
if (x.lastError() != ERROR_FILE_NOT_FOUND &&
|
||||||
|
x.lastError() != ERROR_PATH_NOT_FOUND) {
|
||||||
x.rethrowAsIOException(target);
|
x.rethrowAsIOException(target);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// first try MoveFileEx (no options). If target is on same volume then
|
// first try MoveFileEx (no options). If target is on same volume then
|
||||||
// all attributes (including security attributes) are preserved.
|
// all attributes (including security attributes) are preserved.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user