Skip to content

Commit 7ae39b3

Browse files
authored
Merge pull request #200 from volllly/fix/link-file-not-existing
Fix creating empty symlinks if the source file does not exist
2 parents 6ba59ab + 6673089 commit 7ae39b3

4 files changed

Lines changed: 18 additions & 3 deletions

File tree

CHANGELOG.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
66

77
## [Unreleased]
88

9+
## [0.9.3] - 2023-02-12
10+
11+
### Fixed
12+
13+
- Issue where rotz would create empty symlinks if the source file does not exist
14+
915
## [0.9.2] - 2023-01-18
1016

1117
### Fixed
@@ -192,7 +198,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
192198
- Dotfile linking
193199
- Error handling
194200

195-
[Unreleased]: https://github.com/volllly/rotz/compare/v0.9.2...HEAD
201+
[Unreleased]: https://github.com/volllly/rotz/compare/v0.9.3...HEAD
202+
[0.9.3]: https://github.com/volllly/rotz/releases/tag/v0.9.3
196203
[0.9.2]: https://github.com/volllly/rotz/releases/tag/v0.9.2
197204
[0.9.1]: https://github.com/volllly/rotz/releases/tag/v0.9.1
198205
[0.9.0]: https://github.com/volllly/rotz/releases/tag/v0.9.0

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "rotz"
3-
version = "0.9.2"
3+
version = "0.9.3"
44
edition = "2021"
55
authors = ["Paul Volavsek <paul.volavsek@gmail.com>"]
66
license = "MIT"

src/commands/link.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ enum Error {
3636
#[error("The file \"{0}\" already exists")]
3737
#[diagnostic(code(link::already_exists), help("Try using the --force flag"))]
3838
AlreadyExists(PathBuf),
39+
40+
#[error("The link source file \"{0}\" does not exist exists")]
41+
#[diagnostic(code(link::does_not_exist), help("Maybe you have a typo in the filename?"))]
42+
LinkSourceDoesNotExist(PathBuf),
3943
}
4044

4145
pub(crate) struct Link<'a> {
@@ -161,6 +165,10 @@ impl<'a> Command for Link<'a> {
161165

162166
#[cfg_attr(feature = "profiling", instrument)]
163167
fn create_link(from: &Path, to: &Path, link_type: &LinkType, force: bool, linked: Option<&HashMap<PathBuf, PathBuf>>) -> std::result::Result<(), Error> {
168+
if !from.exists() {
169+
return Error::LinkSourceDoesNotExist(from.to_path_buf()).pipe(Err);
170+
}
171+
164172
let create: fn(&Path, &Path) -> std::result::Result<(), std::io::Error> = if link_type.is_symbolic() { symlink } else { hardlink };
165173

166174
match create(from, to) {

0 commit comments

Comments
 (0)