Skip to content

Commit

Permalink
Make deletion transactional
Browse files Browse the repository at this point in the history
  • Loading branch information
stefan-kolb committed Sep 29, 2015
1 parent 33d18a4 commit 9c43d30
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 22 deletions.
20 changes: 15 additions & 5 deletions src/main/java/net/sf/jabref/gui/fieldeditors/FileListEditor.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
import java.awt.event.MouseEvent;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;

import javax.swing.AbstractAction;
import javax.swing.JButton;
Expand Down Expand Up @@ -253,11 +255,19 @@ public void actionPerformed(ActionEvent e) {
}

FileListEntry entry = tableModel.getEntry(row);
// unlink file
removeEntries();
// delete file from filesystem
File expandedPath = FileUtil.expandFilename(metaData, entry.getLink());
FileUtil.deleteFile(expandedPath.getAbsolutePath());
Path filePath = FileUtil.expandFilename(metaData, entry.getLink()).toPath();

try {
// transactional delete and unlink
if(Files.exists(filePath)) {
Files.delete(filePath);
removeEntries();
} else {
removeEntries();
}
} catch (IOException ex) {
LOGGER.warn("File permission error while deleting: " + filePath);
}
}
});
}
Expand Down
17 changes: 0 additions & 17 deletions src/main/java/net/sf/jabref/logic/util/io/FileUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -96,23 +96,6 @@ public static boolean renameFile(String fileName, String destFilename) {
return fromFile.renameTo(toFile);
}

/**
* Deletes a file from the local file system.
*
* @param filePath the file to delete
*/
public static void deleteFile(String filePath) {
try {
Files.delete(Paths.get(filePath));
} catch (NoSuchFileException e) {
LOGGER.warn("No such file or directory found: " + filePath);
} catch (DirectoryNotEmptyException e) {
LOGGER.warn("Cannot delete non-empty directory: " + filePath);
} catch (IOException e) {
LOGGER.warn("File permission error while deleting: " + filePath);
}
}

/**
* Converts a relative filename to an absolute one, if necessary. Returns
* null if the file does not exist.<br/>
Expand Down

0 comments on commit 9c43d30

Please sign in to comment.