Skip to content
This repository has been archived by the owner on Jul 4, 2024. It is now read-only.

Commit

Permalink
Automatically cut too long path segments
Browse files Browse the repository at this point in the history
  • Loading branch information
bytedream committed Apr 25, 2024
1 parent 74aaed4 commit cf8bfb0
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion crunchy-cli-core/src/utils/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,33 @@ impl Format {
),
);

PathBuf::from(path)
let mut path = PathBuf::from(path);

// make sure that every path section has a maximum of 255 characters
if path.file_name().unwrap_or_default().to_string_lossy().len() > 255 {
let name = path
.file_stem()
.unwrap_or_default()
.to_string_lossy()
.to_string();
let ext = path
.extension()
.unwrap_or_default()
.to_string_lossy()
.to_string();
if ext != name {
path.set_file_name(format!("{}.{}", &name[..(255 - ext.len() - 1)], ext))
}
}
path.into_iter()
.map(|s| {
if s.len() > 255 {
s.to_string_lossy()[..255].to_string()
} else {
s.to_string_lossy().to_string()
}
})
.collect()
}

pub fn visual_output(&self, dst: &Path) {
Expand Down

0 comments on commit cf8bfb0

Please sign in to comment.