public void removeBlock(long blockId) { transactionIds.remove(blockId); headerIds.remove(blockId); BitCoopFile fileToDelete = getFileForId(blockId); if (fileToDelete != null) { fileToDelete.delete(); } }
/*junit*/ long getUsedSpace(BitCoopFile rootFile) { if (rootFile.isFile()) return rootFile.length(); long size = 0; BitCoopFile[] files = rootFile.listFiles(); if (files == null) return 0; for (BitCoopFile file : files) { size += getUsedSpace(file); } return size; }
private void deleteTree(BitCoopFile root) { BitCoopFile childs[] = root.listFiles(); if (childs != null) { for (BitCoopFile child : childs) { deleteTree(child); } } if (root.delete() == false) { Logger.getLogger(this.getClass()).error("Delete failed for file " + root); } }
/** * @param repositoryManager * @param peerName * @throws FileNotFoundException */ public FSBlockRepository(FSRepositoryManager repositoryManager, String directoryPath) { super(repositoryManager); if (directoryPath == null) { throw new RuntimeException("DirectoryPath cannot be null"); } this.directoryPath = directoryPath; this.usedSpace = getUsedSpace(); try { BitCoopFile dirFile = new BitCoopFile(directoryPath); dirFile.mkdirs(); openIndex(); } catch (Exception e) { e.printStackTrace(); throw new RuntimeException(e); } }
/*junit*/ BitCoopFile getFileForId(long blockId) { BitCoopFile parent = new BitCoopFile(getFilePath(blockId)); parent.mkdirs(); return new BitCoopFile(parent, "data"); }