The Daily WTF
Today’s anonymous submitter works on a project which uses Apache Derby to provide database services. Derby is a tiny database you can embed into your Java application, like SQLite. Even though it’s part of the application, that doesn’t mean it doesn’t need to be backed up from time to time.
Our submitter was handed the code because the backup feature was “peculiar”, and failed for reasons no one had figured out yet. It didn’t take too long to figure out that the failures were triggered by not having enough space on the device for a backup. But they definitely had a enoughFreeSpaceForBackup check, so what was going wrong?
private boolean enoughFreeSpaceForBackup() throws IOException { final Path databaseDir = workingDirectory.resolve(“database”); // resolve folder where database is written to final FileStore store = Files.getFileStore(workingDirectory.getRoot()); // get the filestore final long backupFreeSpace = store.getTotalSpace(); // get the … yes … total size of
To read the full article click on the 'post' link at the top.