Problem with built-in path normalization

Open
#263 2 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
35/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
rust
Domain
tooling

Research direction

Start with tar-rs/src/header.rs around the linked normalization code and the Builder::append_dir_all entry point. Determine whether the current API can preserve a root . component, then verify that the generated archive contains ./, ./manifest, and ./control in the requested structure.

Written by the indexing model from the issue text.

Description

I have a use case where I need to create a debian-like package format.
In a nutshell, I have to create a tar file with the following entries structure:

/./
- /./manifest
- /./control

where the root entry is indeed named .

Is there a way to create this (valid) tar file with tar-rs?
I tried different ways but failed.

What I expected to work was the following:

fn create_tar_gz(filepath: &Path, dir: &Path) -> io::Result<()> {
    let archive = std::fs::File::create(filepath)?;
    let enc = GzEncoder::new(archive, Compression::default());
    let mut tar = tar::Builder::new(enc);
    tar.append_dir_all("./.", dir)?;
    tar.finish()?;
    Ok(())

However, it creates a tar file with the following structure:

manifest
control
/./
- empty entry directory

... because the current dir component gets stripped away here:

https://github.com/alexcrichton/tar-rs/blob/60c6bd81d73fd0e340cfb0e147aae13ce23e18c6/src/header.rs#L1502

Just changing this line to:

            (Component::CurDir, false) => {},

fixes the problem.

I have the following questions:

  1. Is there a way to create the desired tar file with the current API provided by tar-rs?
  2. If no, would a contribution be accepted for making it work and if so, what would the requirements for that be/how should that look like?

Thanks!

Dominant language
Rust
Stars
739
Forks
245
PR merge metrics
No merged PRs in 30d

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from composefs/tar-rs

All issues in composefs/tar-rs

Similar issues

More Rust issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.