Skip to content
This repository has been archived by the owner on Mar 5, 2023. It is now read-only.

Commit

Permalink
Storage: Add backupAddressBook(ReadOnlyAddressBook)
Browse files Browse the repository at this point in the history
Storage saves to a single file path.

Users may want to do a backup of the address book in a different
location.

Let's add Storage#backupAddressBook(ReadOnlyAddressBook).
  • Loading branch information
yamgent committed Aug 18, 2018
1 parent 83699f1 commit ff7373c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,5 @@ public interface AddressBookStorage {
*/
void saveAddressBook(ReadOnlyAddressBook addressBook, Path filePath) throws IOException;

void backupAddressBook(ReadOnlyAddressBook addressBook) throws IOException;
}
4 changes: 4 additions & 0 deletions src/main/java/seedu/address/storage/StorageManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ public void saveAddressBook(ReadOnlyAddressBook addressBook, Path filePath) thro
addressBookStorage.saveAddressBook(addressBook, filePath);
}

@Override
public void backupAddressBook(ReadOnlyAddressBook addressBook) throws IOException {
addressBookStorage.backupAddressBook(addressBook);
}

@Override
@Subscribe
Expand Down
10 changes: 9 additions & 1 deletion src/main/java/seedu/address/storage/XmlAddressBookStorage.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Optional;
import java.util.logging.Logger;

Expand All @@ -22,10 +23,12 @@ public class XmlAddressBookStorage implements AddressBookStorage {

private static final Logger logger = LogsCenter.getLogger(XmlAddressBookStorage.class);

private Path filePath;
private final Path filePath;
private final Path backupFilePath;

public XmlAddressBookStorage(Path filePath) {
this.filePath = filePath;
this.backupFilePath = Paths.get(filePath.toString() + ".backup");
}

public Path getAddressBookFilePath() {
Expand Down Expand Up @@ -60,6 +63,11 @@ public Optional<ReadOnlyAddressBook> readAddressBook(Path filePath) throws DataC
}
}

@Override
public void backupAddressBook(ReadOnlyAddressBook addressBook) throws IOException {
saveAddressBook(addressBook, backupFilePath);
}

@Override
public void saveAddressBook(ReadOnlyAddressBook addressBook) throws IOException {
saveAddressBook(addressBook, filePath);
Expand Down

0 comments on commit ff7373c

Please sign in to comment.