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

Installing directories #12

Open
olivierlemasle opened this issue Sep 15, 2022 · 2 comments
Open

Installing directories #12

olivierlemasle opened this issue Sep 15, 2022 · 2 comments
Assignees
Labels
good first issue Good for newcomers

Comments

@olivierlemasle
Copy link
Collaborator

Is it possible to install directories with rpm-rs?
I only found the way to install files, but not their parent directory, which leads to the creation of unowned / orphaned directories.

@olivierlemasle
Copy link
Collaborator Author

olivierlemasle commented Sep 21, 2022

I've now found that it is currently not possible to install directories with rpm-rs.

Issues

  1. Installing then uninstalling a RPM package may leave some empty directories (unowned / orphaned). For example:

    1. Generate a RPM package with:

      let pkg = rpm::RPMBuilder::new("awesome", "1.0.0", "MIT", "x86_64", "awesome rpm")
          .with_file(
              "./test_assets/awesome.toml",
              rpm::RPMFileOptions::new("/etc/awesome/awesome.toml"),
          )?
          .build()?;
      let mut f = fs::File::create("./awesome.rpm")?;
      pkg.write(&mut f)?;
    2. Install then remove the package:

      # ls -al /etc/awesome/
      ls: cannot access '/etc/awesome/': No such file or directory
      
      # rpm -i ./awesome.rpm
      
      # ls -al /etc/awesome/
      total 20
      drwxr-xr-x    2 root root  4096 Sep 21 11:22 .
      drwxr-xr-x. 205 root root 12288 Sep 21 11:22 ..
      -rw-r--r--    1 root root    31 Sep 12 10:27 awesome.toml
      
      # rpm -e awesome
      
      # ls -al /etc/awesome/
      total 16
      drwxr-xr-x    2 root root  4096 Sep 21 11:22 .
      drwxr-xr-x. 205 root root 12288 Sep 21 11:22 ..
      
  2. There's no way to simply install an empty directory (e.g. /var/log/awesome with proper permissions)

Solutions

I've made it work on my side, but before opening a Pull Request, I'd like to discuss the API...

As there's no content for an empty directory, there's no need to pass
a source... except for copying metadata (modified_at and default permissions). So we could do something like:

builder
    .with_dir(
        "./test_assets", // just used to copy metadata
        RPMFileOptions::new("/etc/awesome")
            .mode(rpm::FileMode::dir(0o644)) // need to use FileMode::dir
    )?
    .with_file(
        "./test_assets/awesome.toml",
        RPMFileOptions::new("/etc/awesome/awesome.toml"),
    )?

or:

builder
    .with_dir(
        RPMDirectoryOptions::new("/etc/awesome", modified_at)
            .mode(rpm::FileMode::dir(0o644)) // With RPMDirectoryOptions, this could be the default value
    )?
    .with_file(
        "./test_assets/awesome.toml",
        RPMFileOptions::new("/etc/awesome/awesome.toml"),
    )?

or:

builder
    .with_dir("/etc/awesome", modified_at, 0o644, RPMDirectoryOptions::new())?
    // options would still be used for e.g flag
    .with_file(
        "./test_assets/awesome.toml",
        RPMFileOptions::new("/etc/awesome/awesome.toml"),
    )?

What are your thoughts?

Should modified_at be required or should we provide a default value (e.g. now)?

Should we have two types of options for files and directories?

Should we give a path as a "model" for permissions and modified_at?

Of course, before opening a Pull Request, I'll wait for your feedback here, and the clarification of this fork's future.

@drahnr
Copy link
Contributor

drahnr commented Nov 11, 2022

I think the RPMFileOptions are just broken, the interface should handle this.

Note: I am not sure how ownership is tracked in rpmdb, of directories. I.e. what happens if multiple packages claim ownership of a directory? /usr i.e. is shared by many. I currently don't have the time to investigate this thoroughly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

3 participants