summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2020-12-26 10:09:44 +0200
committerLars Wirzenius <liw@liw.fi>2020-12-26 10:27:19 +0200
commit2f95edc25f127fd5ac1fb9df96bf8489dbece3ec (patch)
tree569506cb6e5cfdb7e3d2e8f6ff6cb9bdb7971665
parent62b533e319f8a67db908a541c48b2d3a25edeb58 (diff)
downloadobnam2-2f95edc25f127fd5ac1fb9df96bf8489dbece3ec.tar.gz
feat! store pathnames a vectors of bytes
This is the most generic way to store filenames.
-rw-r--r--src/fsentry.rs9
1 files changed, 6 insertions, 3 deletions
diff --git a/src/fsentry.rs b/src/fsentry.rs
index 844642a..471b1bd 100644
--- a/src/fsentry.rs
+++ b/src/fsentry.rs
@@ -1,7 +1,9 @@
use serde::{Deserialize, Serialize};
+use std::ffi::OsString;
use std::fs::read_link;
use std::fs::{FileType, Metadata};
use std::os::linux::fs::MetadataExt;
+use std::os::unix::ffi::OsStringExt;
use std::path::{Path, PathBuf};
/// A file system entry.
@@ -16,7 +18,7 @@ use std::path::{Path, PathBuf};
#[derive(Debug, Serialize, Deserialize)]
pub struct FilesystemEntry {
kind: FilesystemKind,
- path: PathBuf,
+ path: Vec<u8>,
len: u64,
// 16 bits should be enough for a Unix mode_t.
@@ -40,7 +42,7 @@ impl FilesystemEntry {
pub fn from_metadata(path: &Path, meta: &Metadata) -> anyhow::Result<Self> {
let kind = FilesystemKind::from_file_type(meta.file_type());
Ok(Self {
- path: path.to_path_buf(),
+ path: path.to_path_buf().into_os_string().into_vec(),
kind: FilesystemKind::from_file_type(meta.file_type()),
len: meta.len(),
mode: meta.st_mode(),
@@ -61,7 +63,8 @@ impl FilesystemEntry {
}
pub fn pathbuf(&self) -> PathBuf {
- self.path.to_path_buf()
+ let path = self.path.clone();
+ PathBuf::from(OsString::from_vec(path))
}
pub fn len(&self) -> u64 {