private boolean copyDatabaseLocked(File toDir) { if (!(toDir.mkdirs() || toDir.isDirectory())) { Logger.e(Logger.LOG_TAG, "Error creating directories for database copy"); return false; } File dbFile = new File(getDatabasePath()); try { if (copyFileIfExists(dbFile, toDir)) { copyFileIfExists(new File(dbFile.getPath() + "-journal"), toDir); copyFileIfExists(new File(dbFile.getPath() + "-shm"), toDir); copyFileIfExists(new File(dbFile.getPath() + "-wal"), toDir); } else { Logger.e(Logger.LOG_TAG, "Attempted to copy database " + getName() + " but it doesn't exist yet"); return false; } } catch (IOException e) { Logger.e(Logger.LOG_TAG, "Error copying database " + getName(), e); return false; } return true; }
private String attachTo(SquidDatabase attachTo) { if (attachedTo != null) { throw new IllegalArgumentException( "Database " + getName() + " is already attached to " + attachedTo.getName()); } if (inTransaction()) { throw new IllegalStateException( "Cannot attach database " + getName() + " to " + attachTo.getName() + " -- " + getName() + " is in a transaction on the calling thread"); } acquireExclusiveLock(); String attachedAs = getAttachedName(); if (!attachTo.tryExecSql("ATTACH '" + getDatabasePath() + "' AS '" + attachedAs + "'")) { releaseExclusiveLock(); // Failed return null; } else { attachedTo = attachTo; return attachedAs; } }
private boolean copyDatabaseLocked(File toDir) { if (!(toDir.mkdirs() || toDir.isDirectory())) { Logger.e(Logger.LOG_TAG, "Error creating directories for database copy"); return false; } File dbFile = new File(getDatabasePath()); try { if (copyFileIfExists(dbFile, toDir)) { copyFileIfExists(new File(dbFile.getPath() + "-journal"), toDir); copyFileIfExists(new File(dbFile.getPath() + "-shm"), toDir); copyFileIfExists(new File(dbFile.getPath() + "-wal"), toDir); } else { Logger.e(Logger.LOG_TAG, "Attempted to copy database " + getName() + " but it doesn't exist yet"); return false; } } catch (IOException e) { Logger.e(Logger.LOG_TAG, "Error copying database " + getName(), e); return false; } return true; }
private String attachTo(SquidDatabase attachTo) { if (attachedTo != null) { throw new IllegalArgumentException( "Database " + getName() + " is already attached to " + attachedTo.getName()); } if (inTransaction()) { throw new IllegalStateException( "Cannot attach database " + getName() + " to " + attachTo.getName() + " -- " + getName() + " is in a transaction on the calling thread"); } acquireExclusiveLock(); String attachedAs = getAttachedName(); if (!attachTo.tryExecSql("ATTACH '" + getDatabasePath() + "' AS '" + attachedAs + "'")) { releaseExclusiveLock(); // Failed return null; } else { attachedTo = attachTo; return attachedAs; } }