diff options
author | Lars Wirzenius <liw@liw.fi> | 2020-12-26 10:05:58 +0200 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2020-12-26 10:26:58 +0200 |
commit | 62b533e319f8a67db908a541c48b2d3a25edeb58 (patch) | |
tree | 866cae345a0c76538f0ff07df01f4c16e69e6bb2 | |
parent | 6cf8ec1898e70ba3e625f647f3dc3bf3f820299a (diff) | |
download | obnam2-62b533e319f8a67db908a541c48b2d3a25edeb58.tar.gz |
refactor: rename FileSystemEntry::path to pathbuf
This is a step towards changing how filenames are stored in FileSystemEntry.
-rw-r--r-- | src/client.rs | 6 | ||||
-rw-r--r-- | src/cmd/backup.rs | 5 | ||||
-rw-r--r-- | src/cmd/restore.rs | 11 | ||||
-rw-r--r-- | src/fsentry.rs | 4 |
4 files changed, 14 insertions, 12 deletions
diff --git a/src/client.rs b/src/client.rs index af8d65e..3149ec5 100644 --- a/src/client.rs +++ b/src/client.rs @@ -62,7 +62,7 @@ impl BackupClient { ) -> anyhow::Result<(FilesystemEntry, Vec<ChunkId>)> { debug!("entry: {:?}", e); let ids = match e.kind() { - FilesystemKind::Regular => self.read_file(e.path(), size)?, + FilesystemKind::Regular => self.read_file(e.pathbuf(), size)?, FilesystemKind::Directory => vec![], FilesystemKind::Symlink => vec![], }; @@ -70,7 +70,7 @@ impl BackupClient { } pub fn upload_generation(&self, filename: &Path, size: usize) -> anyhow::Result<ChunkId> { - let ids = self.read_file(filename, size)?; + let ids = self.read_file(filename.to_path_buf(), size)?; let gen = GenerationChunk::new(ids); let data = gen.to_data_chunk()?; let meta = ChunkMeta::new_generation(&sha256(data.data()), "timestamp"); @@ -78,7 +78,7 @@ impl BackupClient { Ok(gen_id) } - fn read_file(&self, filename: &Path, size: usize) -> anyhow::Result<Vec<ChunkId>> { + fn read_file(&self, filename: PathBuf, size: usize) -> anyhow::Result<Vec<ChunkId>> { info!("uploading {}", filename.display()); let file = std::fs::File::open(filename)?; let chunker = Chunker::new(size, file); diff --git a/src/cmd/backup.rs b/src/cmd/backup.rs index 3303566..2a294f5 100644 --- a/src/cmd/backup.rs +++ b/src/cmd/backup.rs @@ -30,8 +30,9 @@ pub fn backup(config: &ClientConfig, buffer_size: usize) -> anyhow::Result<()> { match entry { Err(err) => Err(err), Ok(entry) => { - info!("backup: {}", entry.path().display()); - progress.set_message(&format!("{}", entry.path().display())); + let path = &entry.pathbuf(); + info!("backup: {}", path.display()); + progress.set_message(&format!("{}", path.display())); client.upload_filesystem_entry(entry, buffer_size) } } diff --git a/src/cmd/restore.rs b/src/cmd/restore.rs index b4a8f2b..da654fd 100644 --- a/src/cmd/restore.rs +++ b/src/cmd/restore.rs @@ -81,7 +81,7 @@ fn restore_generation( progress: &ProgressBar, ) -> anyhow::Result<()> { debug!("restoring {:?}", entry); - progress.set_message(&format!("{}", entry.path().display())); + progress.set_message(&format!("{}", entry.pathbuf().display())); progress.inc(1); let to = restored_path(entry, to)?; @@ -112,10 +112,11 @@ fn restore_directory_metadata(entry: &FilesystemEntry, to: &Path) -> anyhow::Res } fn restored_path(entry: &FilesystemEntry, to: &Path) -> anyhow::Result<PathBuf> { - let path = if entry.path().is_absolute() { - entry.path().strip_prefix("/")? + let path = &entry.pathbuf(); + let path = if path.is_absolute() { + path.strip_prefix("/")? } else { - entry.path() + path }; Ok(to.join(path)) } @@ -158,7 +159,7 @@ fn restore_symlink(path: &Path, entry: &FilesystemEntry) -> anyhow::Result<()> { } fn restore_metadata(path: &Path, entry: &FilesystemEntry) -> anyhow::Result<()> { - debug!("restoring metadata for {}", entry.path().display()); + debug!("restoring metadata for {}", entry.pathbuf().display()); let handle = File::open(path)?; diff --git a/src/fsentry.rs b/src/fsentry.rs index c66e3e0..844642a 100644 --- a/src/fsentry.rs +++ b/src/fsentry.rs @@ -60,8 +60,8 @@ impl FilesystemEntry { self.kind } - pub fn path(&self) -> &Path { - &self.path + pub fn pathbuf(&self) -> PathBuf { + self.path.to_path_buf() } pub fn len(&self) -> u64 { |