private OFileClassic createFile(String fileName) { OFileClassic fileClassic = new OFileClassic(); String path = storageLocal .getVariableParser() .resolveVariables(storageLocal.getStoragePath() + File.separator + fileName); fileClassic.init(path, storageLocal.getMode()); return fileClassic; }
public boolean exists(String fileName) { synchronized (syncObject) { if (nameIdMap != null && nameIdMap.containsKey(fileName)) return true; final File file = new File( storageLocal .getVariableParser() .resolveVariables(storageLocal.getStoragePath() + File.separator + fileName)); return file.exists(); } }
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 void initNameIdMapping() throws IOException { if (nameIdMapHolder == null) { final File storagePath = new File(storageLocal.getStoragePath()); if (!storagePath.exists()) if (!storagePath.mkdirs()) throw new OStorageException("Can not create directories for the path " + storagePath); nameIdMapHolderFile = new File(storagePath, NAME_ID_MAP); nameIdMapHolder = new RandomAccessFile(nameIdMapHolderFile, "rw"); readNameIdMap(); } }