Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
import java.util.concurrent.ExecutorService;

import org.apache.commons.io.FileUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.uberfire.java.nio.IOException;
import org.uberfire.java.nio.base.BasicFileAttributesImpl;
import org.uberfire.java.nio.base.ExtendedAttributeView;
Expand Down Expand Up @@ -73,8 +75,10 @@

public class SimpleFileSystemProvider implements FileSystemProvider {

private static final Logger LOGGER = LoggerFactory.getLogger(SimpleFileSystemProvider.class);
private static final String STREAM_CLOSED = "This stream is closed.";
private static final String USER_DIR = "user.dir";

protected BaseSimpleFileSystem fileSystem;
private final OSType osType;
private final File[] roots;
Expand Down Expand Up @@ -419,7 +423,7 @@ public void delete(final Path path,
@Override
public boolean deleteIfExists(final Path path,
final DeleteOption... options)
throws DirectoryNotEmptyException, IOException, SecurityException {
throws IOException, SecurityException {
checkNotNull("path",
path);
synchronized (this) {
Expand All @@ -430,16 +434,18 @@ public boolean deleteIfExists(final Path path,
throw new DirectoryNotEmptyException(path.toString());
}

final boolean result = file.exists();
boolean fileRemoved = file.exists();

try {
FileUtils.forceDelete(file);
} catch (final FileNotFoundException ignore) {
} catch (java.io.IOException e) {
throw new IOException(e);
if (file.exists()) {
try {
FileUtils.forceDelete(file);
} catch (java.io.IOException e) {
fileRemoved = false;
LOGGER.error("Error trying to delete file {}", file.getAbsolutePath(), e);
}
}

return result;
return fileRemoved;
} finally {
toGeneralPathImpl(path).clearCache();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,7 @@ public void checkDeleteIfExists() throws IOException {
assertThat(path.toFile()).doesNotExist();
}

@Test(expected = org.uberfire.java.nio.IOException.class)
@Test
public void checkDeleteIfExistsNonExistent() {
final SimpleFileSystemProvider fsProvider = new SimpleFileSystemProvider();

Expand Down