protected static void doDeleteSyncFile(SyncFile syncFile, boolean notify) throws SQLException { if (syncFile.isFile()) { final Path filePath = IODeltaUtil.getChecksumsFilePath(syncFile); Runnable runnable = new Runnable() { @Override public void run() { try { Files.deleteIfExists(filePath); } catch (IOException ioe) { _logger.error(ioe.getMessage(), ioe); } } }; ExecutorService executorService = SyncEngine.getExecutorService(); executorService.execute(runnable); } _syncFilePersistence.delete(syncFile, notify); }
public static SyncFile updateFileSyncFile(Path filePath, long syncAccountId, SyncFile syncFile) throws Exception { // Local sync file if (FileUtil.getFileKey(filePath) != syncFile.getSyncFileId()) { FileUtil.writeFileKey(filePath, String.valueOf(syncFile.getSyncFileId())); } Path deltaFilePath = null; String name = _getName(filePath, syncFile); String sourceChecksum = syncFile.getChecksum(); String sourceFileName = syncFile.getName(); long sourceVersionId = syncFile.getVersionId(); String targetChecksum = FileUtil.getChecksum(filePath); if (!FileUtil.checksumsEqual(sourceChecksum, targetChecksum) && !IODeltaUtil.isIgnoredFilePatchingExtension(syncFile)) { deltaFilePath = Files.createTempFile(String.valueOf(filePath.getFileName()), ".tmp"); deltaFilePath = IODeltaUtil.delta(filePath, IODeltaUtil.getChecksumsFilePath(syncFile), deltaFilePath); IODeltaUtil.checksums(syncFile); } syncFile.setChecksum(targetChecksum); syncFile.setFilePathName(filePath.toString()); syncFile.setName(name); update(syncFile); // Remote sync file if ((syncFile.getState() != SyncFile.STATE_ERROR) && (syncFile.getState() != SyncFile.STATE_UNSYNCED)) { FileEventUtil.updateFile( filePath, syncAccountId, syncFile, deltaFilePath, name, sourceChecksum, sourceFileName, sourceVersionId, targetChecksum); } return syncFile; }