private static synchronized void deleteFile(DataHandler handler, String fileName) { // synchronize on the database, to avoid concurrent temp file creation / // deletion / backup synchronized (handler.getLobSyncObject()) { FileUtils.delete(fileName); } }
/** * 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); } } }
/** * Delete the target file. */ void deleteStore() { String file = getFileName(); if (file != null) { FileUtils.delete(file); } }
conn.close(); if (deleteOldDb) { FileUtils.delete(backupData); FileUtils.delete(backupIndex); FileUtils.deleteRecursive(backupLobs, false); FileUtils.move(backupLobs, lobs); FileUtils.delete(name + ".h2.db"); throw DbException.toSQLException(e); } finally { if (script != null) { FileUtils.delete(script);
private static void process(String fileName, boolean quiet) { if (FileUtils.isDirectory(fileName)) { // only delete empty directories FileUtils.tryDelete(fileName); } else if (quiet || fileName.endsWith(Constants.SUFFIX_TEMP_FILE) || fileName.endsWith(Constants.SUFFIX_TRACE_FILE)) { FileUtils.tryDelete(fileName); } else { FileUtils.delete(fileName); } }
/** * Compress the store by creating a new file and copying the live pages * there. Temporarily, a file with the suffix ".tempFile" is created. This * file is then renamed, replacing the original file, if possible. If not, * the new file is renamed to ".newFile", then the old file is removed, and * the new file is renamed. This might be interrupted, so it's better to * compactCleanUp before opening a store, in case this method was used. * * @param fileName the file name * @param compress whether to compress the data */ public static void compact(String fileName, boolean compress) { String tempName = fileName + Constants.SUFFIX_MV_STORE_TEMP_FILE; FileUtils.delete(tempName); compact(fileName, tempName, compress); try { FileUtils.moveAtomicReplace(tempName, fileName); } catch (DbException e) { String newName = fileName + Constants.SUFFIX_MV_STORE_NEW_FILE; FileUtils.delete(newName); FileUtils.move(tempName, newName); FileUtils.delete(fileName); FileUtils.move(newName, fileName); } }
/** * 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); } } }
private void copy(String fileName, boolean quiet) throws IOException { if (FileUtils.isDirectory(fileName)) { return; } String temp = directory + "/temp.db"; try (FileChannel fileIn = getFileChannel(fileName, "r", decryptKey)){ try(InputStream inStream = new FileChannelInputStream(fileIn, true)) { FileUtils.delete(temp); try (OutputStream outStream = new FileChannelOutputStream(getFileChannel(temp, "rw", encryptKey), true)) { byte[] buffer = new byte[4 * 1024]; long remaining = fileIn.size(); long total = remaining; long time = System.nanoTime(); while (remaining > 0) { if (!quiet && System.nanoTime() - time > TimeUnit.SECONDS.toNanos(1)) { out.println(fileName + ": " + (100 - 100 * remaining / total) + "%"); time = System.nanoTime(); } int len = (int) Math.min(buffer.length, remaining); len = inStream.read(buffer, 0, len); outStream.write(buffer, 0, len); remaining -= len; } } } } FileUtils.delete(fileName); FileUtils.move(temp, fileName); }
@Override public void remove() { if (fileName != null) { if (tempFile != null) { tempFile.stopAutoDelete(); } // synchronize on the database, to avoid concurrent temp file // creation / deletion / backup synchronized (handler.getLobSyncObject()) { FileUtils.delete(fileName); } } if (handler != null) { handler.getLobStorage().removeLob(this); } }
if (fileName != null) { if (load().equals(properties)) { FileUtils.delete(fileName);
if (maxFileSize > 0 && FileUtils.size(fileName) > maxFileSize) { String old = fileName + ".old"; FileUtils.delete(old); FileUtils.move(fileName, old);
FileUtils.delete(zipFileName); OutputStream fileOut = null; try {
throw getExceptionFatal("Concurrent update", null); FileUtils.delete(fileName); if (!FileUtils.createFile(fileName)) { throw getExceptionFatal("Another process was faster", null);
throw getExceptionAlreadyInUse("Locked by another process: " + fileName); FileUtils.delete(fileName); if (!FileUtils.createFile(fileName)) { throw getExceptionFatal("Another process was faster", null);
FileUtils.delete(temp); FileUtils.move(fileName, temp); FileUtils.move(temp, fileName);
private void dumpLob(String fileName, boolean lobCompression) { OutputStream fileOut = null; FileStore fileStore = null; long size = 0; String n = fileName + (lobCompression ? ".comp" : "") + ".txt"; InputStream in = null; try { fileOut = FileUtils.newOutputStream(n, false); fileStore = FileStore.open(null, fileName, "r"); fileStore.init(); in = new FileStoreInputStream(fileStore, this, lobCompression, false); size = IOUtils.copy(in, fileOut); } catch (Throwable e) { // this is usually not a problem, because we try both compressed and // uncompressed } finally { IOUtils.closeSilently(fileOut); IOUtils.closeSilently(in); closeSilently(fileStore); } if (size == 0) { try { FileUtils.delete(n); } catch (Exception e) { traceError(n, e); } } }
/** * Copy all live pages from the source store to the target store. * * @param sourceFileName the name of the source store * @param targetFileName the name of the target store * @param compress whether to compress the data */ public static void compact(String sourceFileName, String targetFileName, boolean compress) { MVStore source = new MVStore.Builder(). fileName(sourceFileName). readOnly(). open(); FileUtils.delete(targetFileName); MVStore.Builder b = new MVStore.Builder(). fileName(targetFileName); if (compress) { b.compress(); } MVStore target = b.open(); compact(source, target); target.close(); source.close(); }
FileUtils.delete(fileName); openNew(); return;
private static synchronized void deleteFile(DataHandler handler, String fileName) { // synchronize on the database, to avoid concurrent temp file creation / // deletion / backup synchronized (handler.getLobSyncObject()) { FileUtils.delete(fileName); } }