gra-m / DBServer

Database server project
0 stars 0 forks source link

Defragmentation method added #22

Closed gra-m closed 2 years ago

gra-m commented 2 years ago

        String oldDBName = this.fileHandler.getDbFileName();
        boolean oldFileDeleted = this.fileHandler.deleteFile();
        try {
            if (oldFileDeleted) {
                this.fileHandler.close();
                Files.copy(tmpFile.toPath(), FileSystems.getDefault().getPath("", oldDBName),
                        StandardCopyOption.REPLACE_EXISTING);
                this.fileHandler = new FileHandler(oldDBName);
            } else {
                tmpFile.delete();
                this.initialise(); //
                throw new IOException("Old DB file could not be deleted, defrag failed, check logs");
            }
        }catch (IOException e) {
            e.printStackTrace();
        }

![image](https://user-images.githubusercontent.com/91182298/177924071-3e238275-7f6a-4242-bc49-0e9e3b7de05b.png)