diff options
author | Lars Wirzenius <liw@liw.fi> | 2021-02-19 20:19:15 +0200 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2021-02-19 20:19:15 +0200 |
commit | ff17410cbee1492a5ca87869f76a2dafb7f90430 (patch) | |
tree | 0266517f6efc8027c5c58c7634de5e7176ee1a64 /src/cmd | |
parent | 248e5ab7518746c0ac43747040290e9b5d138028 (diff) | |
download | obnam2-ff17410cbee1492a5ca87869f76a2dafb7f90430.tar.gz |
feat: backup and restore named pipes (FIFOs)
Diffstat (limited to 'src/cmd')
-rw-r--r-- | src/cmd/list_files.rs | 1 | ||||
-rw-r--r-- | src/cmd/restore.rs | 18 |
2 files changed, 18 insertions, 1 deletions
diff --git a/src/cmd/list_files.rs b/src/cmd/list_files.rs index 4982cc2..ec3e52e 100644 --- a/src/cmd/list_files.rs +++ b/src/cmd/list_files.rs @@ -36,6 +36,7 @@ fn format_entry(e: &FilesystemEntry, reason: Reason) -> String { FilesystemKind::Directory => "d", FilesystemKind::Symlink => "l", FilesystemKind::Socket => "s", + FilesystemKind::Fifo => "p", }; format!("{} {} ({})", kind, e.pathbuf().display(), reason) } diff --git a/src/cmd/restore.rs b/src/cmd/restore.rs index 147a56b..b394d7d 100644 --- a/src/cmd/restore.rs +++ b/src/cmd/restore.rs @@ -5,7 +5,7 @@ use crate::error::ObnamError; use crate::fsentry::{FilesystemEntry, FilesystemKind}; use crate::generation::{LocalGeneration, LocalGenerationError}; use indicatif::{ProgressBar, ProgressStyle}; -use libc::{chmod, timespec, utimensat, AT_FDCWD}; +use libc::{chmod, mkfifo, timespec, utimensat, AT_FDCWD}; use log::{debug, error, info}; use std::ffi::CString; use std::io::prelude::*; @@ -73,6 +73,9 @@ struct Opt { #[derive(Debug, thiserror::Error)] pub enum RestoreError { + #[error("Could not create named pipe (FIFO) {0}")] + NamedPipeCreationError(PathBuf), + #[error(transparent)] ClientError(#[from] ClientError), @@ -112,6 +115,7 @@ fn restore_generation( FilesystemKind::Directory => restore_directory(&to)?, FilesystemKind::Symlink => restore_symlink(&to, &entry)?, FilesystemKind::Socket => restore_socket(&to, &entry)?, + FilesystemKind::Fifo => restore_fifo(&to, &entry)?, } Ok(()) } @@ -188,6 +192,18 @@ fn restore_socket(path: &Path, entry: &FilesystemEntry) -> RestoreResult<()> { Ok(()) } +fn restore_fifo(path: &Path, entry: &FilesystemEntry) -> RestoreResult<()> { + debug!("creating fifo {:?}", path); + let filename = path_to_cstring(path); + match unsafe { mkfifo(filename.as_ptr(), 0) } { + -1 => { + return Err(RestoreError::NamedPipeCreationError(path.to_path_buf())); + } + _ => restore_metadata(path, entry)?, + } + Ok(()) +} + fn restore_metadata(path: &Path, entry: &FilesystemEntry) -> RestoreResult<()> { debug!("restoring metadata for {}", entry.pathbuf().display()); |