/** * Check if a database with the given name exists. * * @param name the name of the database (including path) * @return true if one exists */ static boolean exists(String name) { if (FileUtils.exists(name + Constants.SUFFIX_PAGE_FILE)) { return true; } return FileUtils.exists(name + Constants.SUFFIX_MV_FILE); }
/** * Clean up if needed, in a case a compact operation was interrupted due to * killing the process or a power failure. This will delete temporary files * (if any), and in case atomic file replacements were not used, rename the * new file. * * @param fileName the file name */ public static void compactCleanUp(String fileName) { String tempName = fileName + Constants.SUFFIX_MV_STORE_TEMP_FILE; if (FileUtils.exists(tempName)) { FileUtils.delete(tempName); } String newName = fileName + Constants.SUFFIX_MV_STORE_NEW_FILE; if (FileUtils.exists(newName)) { if (FileUtils.exists(fileName)) { FileUtils.delete(newName); } else { FileUtils.move(newName, fileName); } } }
/** * 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)) { try (InputStream in = FileUtils.newInputStream(fileName)) { prop.load(in); } } return prop; }
InputStream in = null; try { if (!FileUtils.exists(zipFileName)) { throw new IOException("File not found: " + zipFileName);
if (FileUtils.exists(name + suffix)) { n = FileUtils.toRealPath(name + suffix); } else {
KEYSTORE_PASSWORD), KEYSTORE_PASSWORD); boolean needWrite = true; if (FileUtils.exists(fileName) && FileUtils.size(fileName) == data.length) {
@Override public FileStore openFile(String name, String openMode, boolean mustExist) { if (mustExist && !FileUtils.exists(name)) { throw DbException.get(ErrorCode.FILE_NOT_FOUND_1, name); } FileStore store = FileStore.open(this, name, openMode, cipher, filePasswordHash); try { store.init(); } catch (DbException e) { store.closeSilently(); throw e; } return store; }
FileUtils.move(data, backupData); FileUtils.move(index, backupIndex); if (FileUtils.exists(lobs)) { FileUtils.move(lobs, backupLobs); if (FileUtils.exists(backupData)) { FileUtils.move(backupData, data); if (FileUtils.exists(backupIndex)) { FileUtils.move(backupIndex, index); if (FileUtils.exists(backupLobs)) { FileUtils.move(backupLobs, lobs);
Constants.SUFFIX_PAGE_FILE.length()) + Constants.SUFFIX_MV_FILE; if (FileUtils.exists(mvFileName)) { IOUtils.copyFiles(mvFileName, testDatabase + Constants.SUFFIX_MV_FILE);
/** * Create a new file using the given settings. * * @param handler the callback object * @param name the file name * @param mode the access mode ("r", "rw", "rws", "rwd") */ protected FileStore(DataHandler handler, String name, String mode) { this.handler = handler; this.name = name; try { boolean exists = FileUtils.exists(name); if (exists && !FileUtils.canWrite(name)) { mode = "r"; } else { FileUtils.createDirectories(FileUtils.getParent(name)); } file = FileUtils.open(name, mode); if (exists) { fileLength = file.size(); } } catch (IOException e) { throw DbException.convertIOException( e, "name: " + name + " mode: " + mode); } this.mode = mode; }
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; }
if (!FileUtils.exists(fileName) || FileUtils.lastModified(fileName) != lastWrite) { save();
/** * 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); } } }
/** * 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); } } }
@Override public FileStore openFile(String name, String mode, boolean mustExist) { if (mustExist && !FileUtils.exists(name)) { throw DbException.get(ErrorCode.FILE_NOT_FOUND_1, name); } FileStore store; if (cipher == null) { store = FileStore.open(this, name, mode); } else { store = FileStore.open(this, name, mode, cipher, fileEncryptionKey, 0); } store.setCheckedWriting(false); try { store.init(); } catch (DbException e) { store.closeSilently(); throw e; } return store; }
/** * Open the file and read the header. */ public synchronized void open() { try { metaRootPageId.put(META_TABLE_ID, PAGE_ID_META_ROOT); if (FileUtils.exists(fileName)) { long length = FileUtils.size(fileName); if (length < MIN_PAGE_COUNT * PAGE_SIZE_MIN) { if (database.isReadOnly()) { throw DbException.get( ErrorCode.FILE_CORRUPTED_1, fileName + " length: " + length); } // the database was not fully created openNew(); } else { openExisting(); } } else { openNew(); } } catch (DbException e) { close(); throw e; } }
if (compactFully && FileUtils.exists(fileName)) {
} else { boolean exists = FileUtils.exists(fileName); if (exists && !FileUtils.canWrite(fileName)) {