pub struct Archive<'conn> { /* private fields */ }
Expand description
A SQLite archive.
This is the main type for reading and writing to the archive. You can only access an Archive
within the context of a transaction, which you’ll typically use Connection::exec
for.
A SQLite archive is a SQLite database with a table named sqlar
that conforms to a specific
schema. A SQLite archive may contain other tables, and this library will ignore them.
All file paths in a SQLite archive are relative paths; trying to use an absolute path will result in an error.
All file paths in a SQLite archive are encoded using the database encoding; trying to use a path that is not valid Unicode will result in an error.
Implementations§
Source§impl<'conn> Archive<'conn>
impl<'conn> Archive<'conn>
Sourcepub fn open<'ar, P: AsRef<Path>>(
&'ar mut self,
path: P,
) -> Result<File<'conn, 'ar>>
pub fn open<'ar, P: AsRef<Path>>( &'ar mut self, path: P, ) -> Result<File<'conn, 'ar>>
Create a handle to the file at the given path
.
This doesn’t guarantee that the file actually exists in the archive; it only returns a handle to a file that may or may not exist.
See File::exists
to check if the file actually exists in the archive.
Sourcepub fn list(&mut self) -> Result<ListEntries<'_>>
pub fn list(&mut self) -> Result<ListEntries<'_>>
Return an iterator over the files in this archive.
This is the same as Archive::list_with
, but using the default options.
Sourcepub fn list_with(&mut self, opts: &ListOptions) -> Result<ListEntries<'_>>
pub fn list_with(&mut self, opts: &ListOptions) -> Result<ListEntries<'_>>
Return an iterator over the files in this archive.
This accepts a ListOptions
to sort and filter the results.
This returns an error if mutually exclusive options were specified together in
ListOptions
.
§Examples
List the regular files that are descendants of parent/dir
in descending order by size.
let opts = ListOptions::new().by_size().desc().descendants_of("parent/dir");
for result in archive.list_with(&opts)? {
let entry = result?;
let path = entry.path();
if let FileMetadata::File { size, .. } = entry.metadata() {
println!("{}: {}", path.to_string_lossy(), size);
}
}
Sourcepub fn archive<P: AsRef<Path>, Q: AsRef<Path>>(
&mut self,
from: P,
to: Q,
) -> Result<()>
pub fn archive<P: AsRef<Path>, Q: AsRef<Path>>( &mut self, from: P, to: Q, ) -> Result<()>
Copy the filesystem directory tree at from
into the archive at to
.
This is the same as Archive::archive_with
, but using the default options.
Sourcepub fn archive_with<P: AsRef<Path>, Q: AsRef<Path>>(
&mut self,
from: P,
to: Q,
opts: &ArchiveOptions,
) -> Result<()>
pub fn archive_with<P: AsRef<Path>, Q: AsRef<Path>>( &mut self, from: P, to: Q, opts: &ArchiveOptions, ) -> Result<()>
Copy the directory tree at in the filesystem at from
into the archive at to
.
The file at from
may be either a directory or a regular file.
§Errors
FileNotFound
: There is no file or directory atfrom
.FileNotFound
:ArchiveOptions::children
wastrue
andto
does not exist.NoParentDirectory
: The parent directory ofto
does not exist.NotADirectory
:ArchiveOptions::children
wastrue
and the file atfrom
is not a directory.NotADirectory
:ArchiveOptions::children
wastrue
and the file atto
exists but is not a directory.FileAlreadyExists
: One of the files infrom
would overwrite an existing file in the archive.
Sourcepub fn extract<P: AsRef<Path>, Q: AsRef<Path>>(
&mut self,
from: P,
to: Q,
) -> Result<()>
pub fn extract<P: AsRef<Path>, Q: AsRef<Path>>( &mut self, from: P, to: Q, ) -> Result<()>
Copy the directory tree in the archive at from
into the filesystem at to
.
This is the same as Archive::extract_with
, but using the default options.
Sourcepub fn extract_with<P: AsRef<Path>, Q: AsRef<Path>>(
&mut self,
from: P,
to: Q,
opts: &ExtractOptions,
) -> Result<()>
pub fn extract_with<P: AsRef<Path>, Q: AsRef<Path>>( &mut self, from: P, to: Q, opts: &ExtractOptions, ) -> Result<()>
Copy the directory tree in the archive at from
into the filesystem at to
.
The file at from
may be either a directory or a regular file.
§Errors
FileNotFound
: There is no file or directory in the archive atfrom
.FileNotFound
:ExtractOptions::children
wastrue
andto
does not exist.NoParentDirectory
: The parent directory ofto
does not exist.NotADirectory
:ExtractOptions::children
wastrue
and the file atfrom
is not a directory.NotADirectory
:ExtractOptions::children
wastrue
and the file atto
exists but is not a directory.FileAlreadyExists
: One of the files infrom
would overwrite an existing file in the filesystem.
Sourcepub fn set_umask(&mut self, mode: FileMode)
pub fn set_umask(&mut self, mode: FileMode)
Set the umask for newly created files and directories.
This specifies the mode bits that will not be set, assuming the default mode for regular
files is 666
and the default mode for directories is 777
.
The default umask is FileMode::OTHER_W
(002
).
§Examples
archive.set_umask(FileMode::OTHER_R | FileMode::OTHER_W);
assert_eq!(archive.umask(), FileMode::OTHER_R | FileMode::OTHER_W);