public void renameFile(long fileId, String oldFileName, String newFileName) throws IOException { synchronized (syncObject) { if (!files.containsKey(fileId)) return; final OFileClassic file = files.get(fileId); final String osFileName = file.getName(); if (osFileName.startsWith(oldFileName)) { final File newFile = new File( storageLocal.getStoragePath() + File.separator + newFileName + osFileName.substring( osFileName.lastIndexOf(oldFileName) + oldFileName.length())); boolean renamed = file.renameTo(newFile); while (!renamed) { OMemoryWatchDog.freeMemoryForResourceCleanup(100); renamed = file.renameTo(newFile); } } writeNameIdEntry(new NameFileIdEntry(oldFileName, -1), false); writeNameIdEntry(new NameFileIdEntry(newFileName, fileId), true); nameIdMap.remove(oldFileName); nameIdMap.put(newFileName, fileId); } }
private String doDeleteFile(long fileId) throws IOException { if (isOpen(fileId)) truncateFile(fileId); final OFileClassic fileClassic = files.remove(fileId); String name = null; if (fileClassic != null) { name = fileClassic.getName(); if (fileClassic.exists()) fileClassic.delete(); } return name; }
public OPageDataVerificationError[] checkStoredPages( OCommandOutputListener commandOutputListener) { final int notificationTimeOut = 5000; final List<OPageDataVerificationError> errors = new ArrayList<OPageDataVerificationError>(); synchronized (syncObject) { for (long fileId : files.keySet()) { OFileClassic fileClassic = files.get(fileId); boolean fileIsCorrect; try { if (commandOutputListener != null) commandOutputListener.onMessage("Flashing file " + fileClassic.getName() + "... "); flush(fileId); if (commandOutputListener != null) commandOutputListener.onMessage( "Start verification of content of " + fileClassic.getName() + "file ..."); long time = System.currentTimeMillis(); long filledUpTo = fileClassic.getFilledUpTo(); fileIsCorrect = true; for (long pos = 0; pos < filledUpTo; pos += pageSize) { boolean checkSumIncorrect = false; boolean magicNumberIncorrect = false; byte[] data = new byte[pageSize]; fileClassic.read(pos, data, data.length); long magicNumber = OLongSerializer.INSTANCE.deserializeNative(data, 0); if (magicNumber != MAGIC_NUMBER) { magicNumberIncorrect = true; if (commandOutputListener != null) commandOutputListener.onMessage( "Error: Magic number for page " + (pos / pageSize) + " in file " + fileClassic.getName() + " does not much !!!"); fileIsCorrect = false; } final int storedCRC32 = OIntegerSerializer.INSTANCE.deserializeNative(data, OLongSerializer.LONG_SIZE); final int calculatedCRC32 = calculatePageCrc(data); if (storedCRC32 != calculatedCRC32) { checkSumIncorrect = true; if (commandOutputListener != null) commandOutputListener.onMessage( "Error: Checksum for page " + (pos / pageSize) + " in file " + fileClassic.getName() + " is incorrect !!!"); fileIsCorrect = false; } if (magicNumberIncorrect || checkSumIncorrect) errors.add( new OPageDataVerificationError( magicNumberIncorrect, checkSumIncorrect, pos / pageSize, fileClassic.getName())); if (commandOutputListener != null && System.currentTimeMillis() - time > notificationTimeOut) { time = notificationTimeOut; commandOutputListener.onMessage((pos / pageSize) + " pages were processed ..."); } } } catch (IOException ioe) { if (commandOutputListener != null) commandOutputListener.onMessage( "Error: Error during processing of file " + fileClassic.getName() + ". " + ioe.getMessage()); fileIsCorrect = false; } if (!fileIsCorrect) { if (commandOutputListener != null) commandOutputListener.onMessage( "Verification of file " + fileClassic.getName() + " is finished with errors."); } else { if (commandOutputListener != null) commandOutputListener.onMessage( "Verification of file " + fileClassic.getName() + " is successfully finished."); } } return errors.toArray(new OPageDataVerificationError[errors.size()]); } }