Added support for fifo files

This commit is contained in:
Dennis Schwerdel 2017-06-20 12:58:14 +02:00
parent 9231800f3b
commit 98eb59c3e1
6 changed files with 27 additions and 8 deletions

View File

@ -7,6 +7,7 @@ This project follows [semantic versioning](http://semver.org).
* [added] Added `copy` subcommand * [added] Added `copy` subcommand
* [added] Added support for xattrs in fuse mount * [added] Added support for xattrs in fuse mount
* [added] Added support for block/char devices * [added] Added support for block/char devices
* [added] Added support for fifo files
* [modified] Also documenting common flags in subcommands * [modified] Also documenting common flags in subcommands
* [modified] Using repository aliases (**conversion needed**) * [modified] Using repository aliases (**conversion needed**)
* [modified] Remote path must be absolute * [modified] Remote path must be absolute

View File

@ -307,14 +307,16 @@ The `FileType` describes the type of an inode.
children children
- `Symlink` means a symlink that points to a target - `Symlink` means a symlink that points to a target
- `BlockDevice` means a block device - `BlockDevice` means a block device
- `CharDevice` mean a character device - `CharDevice` means a character device
- `NamedPipe` means a named pipe/fifo
FileType { FileType {
File => 0, File => 0,
Directory => 1, Directory => 1,
Symlink => 2, Symlink => 2,
BlockDevice => 3, BlockDevice => 3,
CharDevice => 4 CharDevice => 4,
NamedPipe => 5
} }

View File

@ -156,7 +156,8 @@ pub fn format_inode_one_line(inode: &Inode) -> String {
FileType::BlockDevice | FileType::CharDevice => { FileType::BlockDevice | FileType::CharDevice => {
let device = inode.device.unwrap_or((0, 0)); let device = inode.device.unwrap_or((0, 0));
format!("{:25}\t{:12}\t{}:{}", inode.name, inode.file_type, device.0, device.1) format!("{:25}\t{:12}\t{}:{}", inode.name, inode.file_type, device.0, device.1)
} },
FileType::NamedPipe => format!("{:25}\t fifo", inode.name)
} }
} }

View File

@ -70,7 +70,8 @@ fn convert_file_type(kind: FileType) -> fuse::FileType {
FileType::File => fuse::FileType::RegularFile, FileType::File => fuse::FileType::RegularFile,
FileType::Symlink => fuse::FileType::Symlink, FileType::Symlink => fuse::FileType::Symlink,
FileType::BlockDevice => fuse::FileType::BlockDevice, FileType::BlockDevice => fuse::FileType::BlockDevice,
FileType::CharDevice => fuse::FileType::CharDevice FileType::CharDevice => fuse::FileType::CharDevice,
FileType::NamedPipe => fuse::FileType::NamedPipe
} }
} }

View File

@ -68,14 +68,16 @@ pub enum FileType {
Directory, Directory,
Symlink, Symlink,
BlockDevice, BlockDevice,
CharDevice CharDevice,
NamedPipe
} }
serde_impl!(FileType(u8) { serde_impl!(FileType(u8) {
File => 0, File => 0,
Directory => 1, Directory => 1,
Symlink => 2, Symlink => 2,
BlockDevice => 3, BlockDevice => 3,
CharDevice => 4 CharDevice => 4,
NamedPipe => 5
}); });
impl fmt::Display for FileType { impl fmt::Display for FileType {
fn fmt(&self, format: &mut fmt::Formatter) -> Result<(), fmt::Error> { fn fmt(&self, format: &mut fmt::Formatter) -> Result<(), fmt::Error> {
@ -84,7 +86,8 @@ impl fmt::Display for FileType {
FileType::Directory => write!(format, "directory"), FileType::Directory => write!(format, "directory"),
FileType::Symlink => write!(format, "symlink"), FileType::Symlink => write!(format, "symlink"),
FileType::BlockDevice => write!(format, "block device"), FileType::BlockDevice => write!(format, "block device"),
FileType::CharDevice => write!(format, "char device") FileType::CharDevice => write!(format, "char device"),
FileType::NamedPipe => write!(format, "named pipe")
} }
} }
} }
@ -181,6 +184,8 @@ impl Inode {
FileType::BlockDevice FileType::BlockDevice
} else if meta.file_type().is_char_device() { } else if meta.file_type().is_char_device() {
FileType::CharDevice FileType::CharDevice
} else if meta.file_type().is_fifo() {
FileType::NamedPipe
} else { } else {
return Err(InodeError::UnsupportedFiletype(path.to_owned())); return Err(InodeError::UnsupportedFiletype(path.to_owned()));
}; };
@ -225,6 +230,13 @@ impl Inode {
return Err(InodeError::Integrity("Symlink without target")) return Err(InodeError::Integrity("Symlink without target"))
} }
}, },
FileType::NamedPipe => {
let name = try!(ffi::CString::new(full_path.as_os_str().as_bytes()).map_err(|_| InodeError::Integrity("Name contains nulls")));
let mode = self.mode | libc::S_IFIFO;
if unsafe { libc::mkfifo(name.as_ptr(), mode) } != 0 {
return Err(InodeError::Create(io::Error::last_os_error(), full_path.clone()));
}
},
FileType::BlockDevice | FileType::CharDevice => { FileType::BlockDevice | FileType::CharDevice => {
let name = try!(ffi::CString::new(full_path.as_os_str().as_bytes()).map_err(|_| InodeError::Integrity("Name contains nulls"))); let name = try!(ffi::CString::new(full_path.as_os_str().as_bytes()).map_err(|_| InodeError::Integrity("Name contains nulls")));
let mode = self.mode | match self.file_type { let mode = self.mode | match self.file_type {

View File

@ -87,6 +87,7 @@ fn inode_from_entry<R: Read>(entry: &mut tar::Entry<R>) -> Result<Inode, Reposit
tar::EntryType::Directory => FileType::Directory, tar::EntryType::Directory => FileType::Directory,
tar::EntryType::Block => FileType::BlockDevice, tar::EntryType::Block => FileType::BlockDevice,
tar::EntryType::Char => FileType::CharDevice, tar::EntryType::Char => FileType::CharDevice,
tar::EntryType::Fifo => FileType::NamedPipe,
_ => return Err(InodeError::UnsupportedFiletype(path.to_path_buf()).into()) _ => return Err(InodeError::UnsupportedFiletype(path.to_path_buf()).into())
}; };
Inode { Inode {
@ -330,7 +331,8 @@ impl Repository {
FileType::Symlink => tar::EntryType::Symlink, FileType::Symlink => tar::EntryType::Symlink,
FileType::Directory => tar::EntryType::Directory, FileType::Directory => tar::EntryType::Directory,
FileType::BlockDevice => tar::EntryType::Block, FileType::BlockDevice => tar::EntryType::Block,
FileType::CharDevice => tar::EntryType::Char FileType::CharDevice => tar::EntryType::Char,
FileType::NamedPipe => tar::EntryType::Fifo
}); });
header.set_cksum(); header.set_cksum();
match inode.data { match inode.data {