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

Storage: Add backupAddressBook(ReadOnlyAddressBook) #594

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
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