Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Does ouch support permissions like --xattrs? #626

Open
RyanGreenup opened this issue Feb 10, 2024 Discussed in #625 · 4 comments
Open

Does ouch support permissions like --xattrs? #626

RyanGreenup opened this issue Feb 10, 2024 Discussed in #625 · 4 comments
Labels
enhancement New feature or request PR-welcome Suggestion was approved, but now we need someone to volunteer for doing it

Comments

@RyanGreenup
Copy link

Discussed in #625

Originally posted by RyanGreenup February 10, 2024
It's common to use tar to backup up a home directory like so:

mount LABEL=ROOT -o subvol=@ /mnt

# use bsdar if gnu tar compiled without xattrs or acls
cd /mnt
x=/root-tarball.tar.gz
bsdtar --acls --xattrs --preserve-permissions -cvaf ${x} .

Users can later extract this with:

bsdtar --acls --xattrs  --numeric-owner -xpzf ${x} /mnt

Is there any support for those properties in Ouch? It would be convenient, atleast for me, if there was a command line flag like -P / --preserve-all-permissions, then one could more simply:

# Compress
cd /mnt
ouch compress -P . ${x}

# Decompress
cd /
ouch decompress -P ${x} .

I had a look at the:

and the crate documentation suggests the following functions:

We'd probably need to add this somewhere around src/archive/tar.rs

If you could offer some guidance, I can try and put together a PR if you'd like?

@RyanGreenup
Copy link
Author

RyanGreenup commented Feb 10, 2024

@RyanGreenup
Copy link
Author

RyanGreenup commented Feb 10, 2024

Tar.rs logic

It seems like the work flow of tar is:

Compress

  1. Make a
    builder
    objectwith a
    Header::newgnu(),
  2. Use builder.append to add files

Decompress

  1. Create an archive and set
  2. Unpack the archive

Examples

  1. Compressing

    For Compressing the example in the
    documentation

    is something like:

    use tar::{Builder, Header};
    
    let mut header = Header::new_gnu();
    
    let mut data: &[u8] = &[1, 2, 3, 4];
    
    let mut builder = Builder::new(Vec::new());
    builder.append(&header, data).unwrap();
    let data = builder.into_inner().unwrap();

    We just need to ensure acls are pulled in.

  2. Decompressing

    This could then be decompressed with unpack_archive like so:

    pub fn unpack_archive(reader: Box<dyn Read>, output_folder: &Path, quiet: bool) -> crate::Result<usize> {
        assert!(output_folder.read_dir().expect("dir exists").count() == 0);
        let mut archive = tar::Archive::new(reader);
    
        // --xattrs
        archive.set_unpack_xattrs(true);
        // --preserver-permissions
        archive.set_preserve_permissions();
        // --numeric-ownership
        archive.set_preserve_ownerships();
    
        // --acls
        // TODO
    
        let mut files_unpacked = 0;
        for file in archive.entries()? {
            let mut file = file?;
    
            file.unpack_in(output_folder)?;
        }
    
        Ok(files_unpacked)
    }

    Does that seem right?

@RyanGreenup
Copy link
Author

I created an issue with tar-rs asking about acls:

Further resources:

@marcospb19
Copy link
Member

If you could offer some guidance, I can try and put together a PR if you'd like?

Sorry for the late response. Unfortunately, I don't think I have the time to give guidance on how to approach this, but we could iterate on the solution in the PR review process.

You're right, Ouch doesn't support --xattrs atm.


I like your idea of having a -P/--preserve-all-permissions flag that covers it all.

In the --help message we also have to explain that these permissions apply for Tar but not for Zip archives 🤔, and state that CLS is not supported yet.

In conclusion, I approve this feature request and a PR (from you or someone else) would be welcomed for reviewing 👍.

@marcospb19 marcospb19 added enhancement New feature or request help wanted We would appreciate being helped to solve this PR-welcome Suggestion was approved, but now we need someone to volunteer for doing it and removed help wanted We would appreciate being helped to solve this labels Feb 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request PR-welcome Suggestion was approved, but now we need someone to volunteer for doing it
Projects
None yet
Development

No branches or pull requests

2 participants