Skip to content

Commit

Permalink
fix: add extra character if folders would cause problems on NTFS
Browse files Browse the repository at this point in the history
Closes #11
  • Loading branch information
Ovyerus committed Nov 16, 2023
1 parent 206847c commit cef75a5
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to
[Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

### Fixed

- Force folders to end with an underscore if they would usually end with a space
or full stop, due to issues with NTFS (#11).

## [0.3.1] - 2023-10-07

### Fixed
Expand Down Expand Up @@ -72,7 +79,7 @@ plan to add in the future.
Initial public release of Bandsnatch.

[unreleased]: https://github.com/Ovyerus/bandsnatch/compare/v0.3.1...HEAD
[0.3.1]: https://github.com/Ovyerus/bandsnatch/compare/v0.3.1
[0.3.1]: https://github.com/Ovyerus/bandsnatch/releases/tag/v0.3.1
[0.3.0]: https://github.com/Ovyerus/bandsnatch/releases/tag/v0.3.0
[0.2.1]: https://github.com/Ovyerus/bandsnatch/releases/tag/v0.2.1
[0.2.0]: https://github.com/Ovyerus/bandsnatch/releases/tag/v0.2.0
Expand Down
5 changes: 4 additions & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@

# TODO: cross compilation
craneLib = crane.lib.${system};
rust = pkgs.rust-bin.stable.latest.default; # TODO: lock
# TODO: lock
rust = pkgs.rust-bin.stable.latest.default.override {
extensions = ["rust-src"];
};

stdenv =
if pkgs.stdenv.isLinux
Expand Down
10 changes: 9 additions & 1 deletion src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::{
};

// From https://github.com/Ezwen/bandcamp-collection-downloader/blob/master/src/main/kotlin/bandcampcollectiondownloader/core/Constants.kt#L7
static REPLACEMENT_CHARS: phf::Map<&'static str, &'static str> = phf_map! {
static REPLACEMENT_CHARS: phf::Map<&str, &str> = phf_map! {
":" => "꞉",
"/" => "/",
"\\" => "⧹",
Expand All @@ -17,13 +17,21 @@ static REPLACEMENT_CHARS: phf::Map<&'static str, &'static str> = phf_map! {
"|" => "∣"
};

// NTFS doesn't like these and pretty much shits itself if you try to do
// anything to files/folders containing em.
static UNSAFE_NTFS_ENDINGS: &[char] = &['.', ' '];

pub fn make_string_fs_safe(s: &str) -> String {
let mut str = s.to_string();

for (from, to) in REPLACEMENT_CHARS.entries() {
str = str.replace(from, to);
}

if UNSAFE_NTFS_ENDINGS.contains(&str.chars().last().unwrap()) {
str.push('_');
}

str
}

Expand Down

0 comments on commit cef75a5

Please sign in to comment.