History

Add remaining docs to get `gix-fs` into 'early' mode.

Sebastian Thiel committed 3 years ago

Commit 5783df21 parent 3456c843 files · +13 −2Browse files

Unified · Split

3 files
  1. README.md +1 −1
  2. gix-fs/src/lib.rs +2 −1
  3. gix-fs/src/symlink.rs +10 −0
README.md+1−1
@@ -83,10 +83,10 @@ is usable to some extent. · 82 unmodified lines
83 * [gix-command](https://github.com/Byron/gitoxide/blob/main/crate-status.md#gix-command)83 * [gix-command](https://github.com/Byron/gitoxide/blob/main/crate-status.md#gix-command)
84 * [gix-prompt](https://github.com/Byron/gitoxide/blob/main/crate-status.md#gix-prompt)84 * [gix-prompt](https://github.com/Byron/gitoxide/blob/main/crate-status.md#gix-prompt)
85 * [gix-refspec](https://github.com/Byron/gitoxide/blob/main/crate-status.md#gix-refspec)85 * [gix-refspec](https://github.com/Byron/gitoxide/blob/main/crate-status.md#gix-refspec)
86 * [gix-fs](https://github.com/Byron/gitoxide/blob/main/crate-status.md#gix-fs)
86 * `gitoxide-core`87 * `gitoxide-core`
87* **very early** _(possibly without any documentation and many rough edges)_88* **very early** _(possibly without any documentation and many rough edges)_
88 * [gix-utils](https://github.com/Byron/gitoxide/blob/main/crate-status.md#gix-utils)89 * [gix-utils](https://github.com/Byron/gitoxide/blob/main/crate-status.md#gix-utils)
89 * [gix-fs](https://github.com/Byron/gitoxide/blob/main/crate-status.md#gix-fs)
90 * [gix-worktree](https://github.com/Byron/gitoxide/blob/main/crate-status.md#gix-worktree)90 * [gix-worktree](https://github.com/Byron/gitoxide/blob/main/crate-status.md#gix-worktree)
91 * [gix-bitmap](https://github.com/Byron/gitoxide/blob/main/crate-status.md#gix-bitmap)91 * [gix-bitmap](https://github.com/Byron/gitoxide/blob/main/crate-status.md#gix-bitmap)
92 * [gix-date](https://github.com/Byron/gitoxide/blob/main/crate-status.md#gix-date)92 * [gix-date](https://github.com/Byron/gitoxide/blob/main/crate-status.md#gix-date)
gix-fs/src/lib.rs+2−1
@@ -1,5 +1,5 @@
1//! A crate with file-system specific utilities.1//! A crate with file-system specific utilities.
2#![deny(rust_2018_idioms)]2#![deny(rust_2018_idioms, missing_docs)]
3#![forbid(unsafe_code)]3#![forbid(unsafe_code)]
4 4
5/// Common knowledge about the worktree that is needed across most interactions with the work tree5/// Common knowledge about the worktree that is needed across most interactions with the work tree
@@ -51,4 +51,5 @@ pub struct Stack { · 45 unmodified lines
51 current_is_directory: bool,51 current_is_directory: bool,
52}52}
53 53
54///
54pub mod stack;55pub mod stack;
gix-fs/src/symlink.rs+10−0
@@ -1,16 +1,21 @@
1use std::{io, io::ErrorKind::AlreadyExists, path::Path};1use std::{io, io::ErrorKind::AlreadyExists, path::Path};
2 2
3#[cfg(not(windows))]3#[cfg(not(windows))]
4/// Create a new symlink at `link` which points to `original`.
4pub fn create(original: &Path, link: &Path) -> io::Result<()> {5pub fn create(original: &Path, link: &Path) -> io::Result<()> {
5 std::os::unix::fs::symlink(original, link)6 std::os::unix::fs::symlink(original, link)
6}7}
7 8
8#[cfg(not(windows))]9#[cfg(not(windows))]
10/// Remove a symlink.
11///
12/// Note that on only on windows this is special.
9pub fn remove(path: &Path) -> io::Result<()> {13pub fn remove(path: &Path) -> io::Result<()> {
10 std::fs::remove_file(path)14 std::fs::remove_file(path)
11}15}
12 16
13// TODO: use the `symlink` crate once it can delete directory symlinks17// TODO: use the `symlink` crate once it can delete directory symlinks
18/// Remove a symlink.
14#[cfg(windows)]19#[cfg(windows)]
15pub fn remove(path: &Path) -> io::Result<()> {20pub fn remove(path: &Path) -> io::Result<()> {
16 if let Ok(meta) = std::fs::metadata(path) {21 if let Ok(meta) = std::fs::metadata(path) {
@@ -25,6 +30,7 @@ pub fn remove(path: &Path) -> io::Result<()> { · 8 unmodified lines
25}30}
26 31
27#[cfg(windows)]32#[cfg(windows)]
33/// Create a new symlink at `link` which points to `original`.
28pub fn create(original: &Path, link: &Path) -> io::Result<()> {34pub fn create(original: &Path, link: &Path) -> io::Result<()> {
29 use std::os::windows::fs::{symlink_dir, symlink_file};35 use std::os::windows::fs::{symlink_dir, symlink_file};
30 // TODO: figure out if links to links count as files or whatever they point at36 // TODO: figure out if links to links count as files or whatever they point at
@@ -36,6 +42,8 @@ pub fn create(original: &Path, link: &Path) -> io::Result<()> { · 5 unmodified lines
36}42}
37 43
38#[cfg(not(windows))]44#[cfg(not(windows))]
45/// Return true if `err` indicates that a file collision happened, i.e. a symlink couldn't be created as the `link`
46/// already exists as filesystem object.
39pub fn is_collision_error(err: &std::io::Error) -> bool {47pub fn is_collision_error(err: &std::io::Error) -> bool {
40 // TODO: use ::IsDirectory as well when stabilized instead of raw_os_error(), and ::FileSystemLoop respectively48 // TODO: use ::IsDirectory as well when stabilized instead of raw_os_error(), and ::FileSystemLoop respectively
41 err.kind() == AlreadyExists49 err.kind() == AlreadyExists
@@ -45,6 +53,8 @@ pub fn is_collision_error(err: &std::io::Error) -> bool { · 3 unmodified lines
45}53}
46 54
47#[cfg(windows)]55#[cfg(windows)]
56/// Return true if `err` indicates that a file collision happened, i.e. a symlink couldn't be created as the `link`
57/// already exists as filesystem object.
48pub fn is_collision_error(err: &std::io::Error) -> bool {58pub fn is_collision_error(err: &std::io::Error) -> bool {
49 err.kind() == AlreadyExists || err.kind() == std::io::ErrorKind::PermissionDenied59 err.kind() == AlreadyExists || err.kind() == std::io::ErrorKind::PermissionDenied
50}60}

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t