private void deleteOldChunkFiles() { for (int i = 0; i < id; i++) { String chunkFileName = getChunkFileName(config, i); if (FileUtils.exists(chunkFileName)) FileUtils.delete(chunkFileName); } }
RedoLog(Map<String, String> config) { this.config = config; if (config.containsKey("log_chunk_size")) logChunkSize = Long.parseLong(config.get("log_chunk_size")); else logChunkSize = DEFAULT_LOG_CHUNK_SIZE; String baseDir = config.get("base_dir"); String logDir = config.get("redo_log_dir"); String storagePath = baseDir + File.separator + logDir; config.put("storagePath", storagePath); if (!FileUtils.exists(storagePath)) FileUtils.createDirectories(storagePath); List<Integer> ids = getAllChunkIds(); int lastId; if (!ids.isEmpty()) lastId = ids.get(ids.size() - 1); else lastId = 0; currentChunk = new RedoLogChunk(lastId, config); }
/** * Delete the given file now. This will remove the reference from the list. * * @param ref the reference as returned by addFile * @param fileName the file name */ public synchronized void deleteFile(Reference<?> ref, String fileName) { if (ref != null) { String f2 = refMap.remove(ref); if (f2 != null) { if (SysProperties.CHECK) { if (fileName != null && !f2.equals(fileName)) { DbException.throwInternalError("f2:" + f2 + " f:" + fileName); } } fileName = f2; } } if (fileName != null && FileUtils.exists(fileName)) { try { IOUtils.trace("TempFileDeleter.deleteFile", fileName, null); FileUtils.tryDelete(fileName); } catch (Exception e) { // TODO log such errors? } } }
/** * Load a properties object from a file. * * @param fileName the name of the properties file * @return the properties object */ public static synchronized SortedProperties loadProperties(String fileName) throws IOException { SortedProperties prop = new SortedProperties(); if (FileUtils.exists(fileName)) { InputStream in = null; try { in = FileUtils.newInputStream(fileName); prop.load(in); } finally { if (in != null) { in.close(); } } } return prop; }
@Override public FileStorage openFile(String name, String openMode, boolean mustExist) { if (mustExist && !FileUtils.exists(name)) { throw DbException.get(ErrorCode.FILE_NOT_FOUND_1, name); } FileStorage fileStorage = FileStorage.open(this, name, openMode, dbSettings.cipher, dbSettings.filePasswordHash); try { fileStorage.init(); } catch (DbException e) { fileStorage.closeSilently(); throw e; } return fileStorage; }
AOStorage(Map<String, Object> config) { super(config); this.db = (IDatabase) config.get("db"); String storagePath = getStoragePath(); DataUtils.checkArgument(storagePath != null, "The storage path may not be null"); if (!FileUtils.exists(storagePath)) FileUtils.createDirectories(storagePath); FilePath dir = FilePath.get(storagePath); for (FilePath fp : dir.newDirectoryStream()) { String mapFullName = fp.getName(); if (mapFullName.startsWith(TEMP_NAME_PREFIX)) { fp.delete(); } } }
private boolean openWriter() { if (printWriter == null) { try { FileUtils.createDirectories(FileUtils.getParent(fileName)); if (FileUtils.exists(fileName) && !FileUtils.canWrite(fileName)) { // read only database: don't log error if the trace file // can't be opened return false; } fileWriter = IOUtils.getBufferedWriter(FileUtils.newOutputStream(fileName, true)); printWriter = new PrintWriter(fileWriter, true); } catch (Exception e) { logWritingError(e); return false; } } return true; }
/** * Delete a directory or file and all subdirectories and files. * * @param path the path * @param tryOnly whether errors should be ignored */ public static void deleteRecursive(String path, boolean tryOnly) { if (exists(path)) { if (isDirectory(path)) { for (String s : newDirectoryStream(path)) { deleteRecursive(s, tryOnly); } } if (tryOnly) { tryDelete(path); } else { delete(path); } } }
/** * Create the directory and all required parent directories. * * @param dir the directory name */ public static void createDirectories(String dir) { if (dir != null) { if (exists(dir)) { if (!isDirectory(dir)) { // this will fail createDirectory(dir); } } else { String parent = getParent(dir); createDirectories(parent); createDirectory(dir); } } }
boolean exists = FileUtils.exists(name); if (exists && !FileUtils.canWrite(name)) { mode = "r";
if (!FileUtils.exists(btreeStoragePath)) FileUtils.createDirectories(btreeStoragePath); else {
@Override public FileStorage openFile(String name, String mode, boolean mustExist) { if (mustExist && !FileUtils.exists(name)) { throw DbException.get(ErrorCode.FILE_NOT_FOUND_1, name); } FileStorage fileStorage; if (cipher == null) { fileStorage = FileStorage.open(this, name, mode); } else { fileStorage = FileStorage.open(this, name, mode, cipher, fileEncryptionKey, 0); } fileStorage.setCheckedWriting(false); try { fileStorage.init(); } catch (DbException e) { fileStorage.closeSilently(); throw e; } return fileStorage; }