/// <exception cref="Couchbase.Lite.CouchbaseLiteException"></exception> private void ReplaceDatabase(string databaseName, InputStream databaseStream, IEnumerator <KeyValuePair <string, InputStream> > attachmentStreams) { try { Database database = GetDatabase(databaseName); string dstAttachmentsPath = database.GetAttachmentStorePath(); OutputStream destStream = new FileOutputStream(new FilePath(database.GetPath())); StreamUtils.CopyStream(databaseStream, destStream); FilePath attachmentsFile = new FilePath(dstAttachmentsPath); FileDirUtils.DeleteRecursive(attachmentsFile); attachmentsFile.Mkdirs(); if (attachmentStreams != null) { StreamUtils.CopyStreamsToFolder(attachmentStreams, attachmentsFile); } database.Open(); database.ReplaceUUIDs(); } catch (FileNotFoundException e) { Log.E(Database.Tag, string.Empty, e); throw new CouchbaseLiteException(Status.InternalServerError); } catch (IOException e) { Log.E(Database.Tag, string.Empty, e); throw new CouchbaseLiteException(Status.InternalServerError); } }
public virtual void ReplaceDatabase(string databaseName, FilePath databaseFile, FilePath attachmentsDirectory) { Database database = GetDatabase(databaseName); string dstAttachmentsPath = database.GetAttachmentStorePath(); FilePath destFile = new FilePath(database.GetPath()); FileDirUtils.CopyFile(databaseFile, destFile); FilePath attachmentsFile = new FilePath(dstAttachmentsPath); FileDirUtils.DeleteRecursive(attachmentsFile); attachmentsFile.Mkdirs(); if (attachmentsDirectory != null) { FileDirUtils.CopyFolder(attachmentsDirectory, attachmentsFile); } database.ReplaceUUIDs(); }
public void ReplaceDatabase(string databaseName, FilePath databaseFile, FilePath attachmentsDirectory) { try { Database database = GetDatabase(databaseName); string dstAttachmentsPath = database.GetAttachmentStorePath(); FilePath destFile = new FilePath(database.GetPath()); FileDirUtils.CopyFile(databaseFile, destFile); FilePath attachmentsFile = new FilePath(dstAttachmentsPath); FileDirUtils.DeleteRecursive(attachmentsFile); attachmentsFile.Mkdirs(); if (attachmentsDirectory != null) { FileDirUtils.CopyFolder(attachmentsDirectory, attachmentsFile); } database.ReplaceUUIDs(); } catch (IOException e) { Log.E(Database.Tag, string.Empty, e); throw new CouchbaseLiteException(Status.InternalServerError); } }
public static Database CreateEmptyDBAtPath(string path, Manager manager) { if (!FileDirUtils.RemoveItemIfExists(path)) { return null; } Database result = new Database(path, manager); FilePath af = new FilePath(result.GetAttachmentStorePath()); //recursively delete attachments path if (!FileDirUtils.DeleteRecursive(af)) { return null; } if (!result.Open()) { return null; } return result; }