///| OsFs - OS filesystem implementation for @bitcore.FileSystem and @bitcore.RepoFileSystem
///|
pub struct OsFs {
dummy : Int
}
///|
pub fn OsFs::new() -> OsFs {
{ dummy: 0 }
}
///|
pub impl @bitcore.FileSystem for OsFs with fn mkdir_p(_self, path) {
ensure_dir(path)
}
///|
pub impl @bitcore.FileSystem for OsFs with fn write_file(_self, path, content) {
@fs.write_bytes_to_file(path, content) catch {
err => raise io_error(err)
}
}
///|
pub impl @bitcore.FileSystem for OsFs with fn write_string(_self, path, content) {
@fs.write_string_to_file(path, content) catch {
err => raise io_error(err)
}
}
///|
pub impl @bitcore.FileSystem for OsFs with fn remove_file(_self, path) {
@fs.remove_file(path) catch {
err => raise io_error(err)
}
}
///|
pub impl @bitcore.FileSystem for OsFs with fn remove_dir(_self, path) {
@fs.remove_dir(path) catch {
err => raise io_error(err)
}
}
///|
pub impl @bitcore.RepoFileSystem for OsFs with fn read_file(_self, path) {
@fs.read_file_to_bytes(path) catch {
err => raise io_error(err)
}
}
///|
pub impl @bitcore.RepoFileSystem for OsFs with fn readdir(_self, path) {
@fs.read_dir(path).to_owned() catch {
err => raise io_error(err)
}
}
///|
pub impl @bitcore.RepoFileSystem for OsFs with fn is_dir(_self, path) {
@fs.is_dir(path) catch {
_ => false
}
}
///|
pub impl @bitcore.RepoFileSystem for OsFs with fn is_file(_self, path) {
@fs.is_file(path) catch {
_ => false
}
}
///|
pub impl @bitcore.RepoFileSystem for OsFs with fn mtime(self, path) {
match @bitio.worktree_entry_meta_sync(self, path) {
Some(meta) => meta.mtime()
None => raise @bitcore.GitError::IoError("Unable to stat path: \{path}")
}
}
///| Promote the trait methods this package calls on a concrete `OsFs`.
///
/// Reaching them through the `impl` alone is deprecated: the compiler asks
/// for either a fully qualified `@bitcore.RepoFileSystem::read_file(fs, ..)`
/// at every call site or one `extend` declaration here.
extend OsFs with @bitcore.FileSystem::{ mkdir_p, write_file, write_string }
///|
extend OsFs with @bitcore.RepoFileSystem::{ is_file, read_file }