/* package for tests */ void clear() { synchronized (lock) { installationId = null; ParseFileUtils.deleteQuietly(file); } } }
public void clearCache() { File[] files = cachePath.listFiles(); if (files == null) { return; } for (File file : files) { ParseFileUtils.deleteQuietly(file); } }
@Override public Void call() { if (file.exists() && !ParseFileUtils.deleteQuietly(file)) { throw new RuntimeException("Unable to delete"); } return null; } }, ParseExecutors.io());
/** * Removes an entry from the local id map on disk. */ private synchronized void removeMapEntry(String localId) { if (!isLocalId(localId)) { throw new IllegalStateException("Tried to get invalid local id: \"" + localId + "\"."); } File file = new File(diskPath, localId); ParseFileUtils.deleteQuietly(file); }
static synchronized void resetInstance() { ParseFileUtils.deleteQuietly(new File(ParsePlugins.get().getFilesDir(), STATE_LOCATION)); instance = null; }
copyFile(srcFile, destFile); if (!srcFile.delete()) { ParseFileUtils.deleteQuietly(destFile); throw new IOException("Failed to delete original file '" + srcFile + "' after copy to '" + destFile + "'");
/** * Removes a file from the file system and any internal caches. */ private void removeFile(File file) { synchronized (lock) { // Remove the data in memory for this command. pendingTasks.remove(file); // Release all the localIds referenced by the command. // Read one command from the cache. JSONObject json; try { json = ParseFileUtils.readFileToJSONObject(file); ParseRESTCommand command = commandFromJSON(json); command.releaseLocalIds(); } catch (Exception e) { // Well, we did our best. We'll just have to leak a localId. } // Delete the command file itself. ParseFileUtils.deleteQuietly(file); } }
static PushRouter pushRouterFromState( File diskState, File oldDiskState, int maxHistoryLength) { JSONObject state = readJSONFileQuietly(diskState); JSONObject historyJSON = (state != null) ? state.optJSONObject("history") : null; PushHistory history = new PushHistory(maxHistoryLength, historyJSON); // If the deserialized push history object doesn't have a last timestamp, we might have to // migrate the last timestamp from the legacy pushState file instead. boolean didMigrate = false; if (history.getLastReceivedTimestamp() == null) { JSONObject oldState = readJSONFileQuietly(oldDiskState); if (oldState != null) { String lastTime = oldState.optString("lastTime", null); if (lastTime != null) { history.setLastReceivedTimestamp(lastTime); } didMigrate = true; } } PushRouter router = new PushRouter(diskState, history); if (didMigrate) { router.saveStateToDisk(); ParseFileUtils.deleteQuietly(oldDiskState); } return router; }
@Test public void testSetSameDoesNotWriteToDisk() { File installationIdFile = new File(temporaryFolder.getRoot(), "installationId"); InstallationId installationId = new InstallationId(installationIdFile); String installationIdString = installationId.get(); ParseFileUtils.deleteQuietly(installationIdFile); installationId.set(installationIdString); assertFalse(installationIdFile.exists()); }
@Test public void testInstallationIdIsRandom() { File installationIdFile = new File(temporaryFolder.getRoot(), "installationId"); String installationIdString = new InstallationId(installationIdFile).get(); ParseFileUtils.deleteQuietly(installationIdFile); assertFalse(installationIdString.equals(new InstallationId(installationIdFile).get())); }
@Test public void testInstallationIdIsCachedInMemory() { File installationIdFile = new File(temporaryFolder.getRoot(), "installationId"); InstallationId installationId = new InstallationId(installationIdFile); String installationIdString = installationId.get(); ParseFileUtils.deleteQuietly(installationIdFile); assertEquals(installationIdString, installationId.get()); }