Skip to content

Commit

Permalink
moss/client: Forbid linking of empty files (fixes #372)
Browse files Browse the repository at this point in the history
Turns out a whole bunch of files are unnecessarily empty and cause havoc
with ext4 by ballooning the link_count for the initially constructed empty file
beyond 65k, the upper limit (`u16`)

Whilst Serpent OS will default to `xfs` or `f2fs` in time, we still need to
eliminate this rather nasty `EMLINK` issue.

Signed-off-by: Ikey Doherty <ikey@serpentos.com>
  • Loading branch information
ikeycode committed Dec 21, 2024
1 parent 53fe266 commit cbd2d3e
Showing 1 changed file with 32 additions and 15 deletions.
47 changes: 32 additions & 15 deletions moss/src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -706,21 +706,38 @@ impl Client {

// Link relative from cache to target
let fp = directory.join(hash);
linkat(
Some(cache),
fp.to_str().unwrap(),
Some(parent),
subpath,
nix::unistd::LinkatFlags::NoSymlinkFollow,
)?;

// Fix permissions
fchmodat(
Some(parent),
subpath,
Mode::from_bits_truncate(item.layout.mode),
nix::sys::stat::FchmodatFlags::NoFollowSymlink,
)?;

match *id {
// Mystery empty-file hash. Do not allow dupes!
// https://github.com/serpent-os/tools/issues/372
0x99aa06d3014798d86001c324468d497f => {
let fd = fcntl::openat(
parent,
subpath,
OFlag::O_CREAT | OFlag::O_WRONLY | OFlag::O_TRUNC,
Mode::from_bits_truncate(item.layout.mode),
)?;
close(fd)?;
}
// Regular file
_ => {
linkat(
Some(cache),
fp.to_str().unwrap(),
Some(parent),
subpath,
nix::unistd::LinkatFlags::NoSymlinkFollow,
)?;

// Fix permissions
fchmodat(
Some(parent),
subpath,
Mode::from_bits_truncate(item.layout.mode),
nix::sys::stat::FchmodatFlags::NoFollowSymlink,
)?;
}
}
}
layout::Entry::Symlink(source, _) => {
symlinkat(source.as_str(), Some(parent), subpath)?;
Expand Down

0 comments on commit cbd2d3e

Please sign in to comment.