Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 714082 - [Future EAPI] fperms, fowners are difficult to use with globs
Summary: [Future EAPI] fperms, fowners are difficult to use with globs
Status: RESOLVED WORKSFORME
Alias: None
Product: Gentoo Hosted Projects
Classification: Unclassified
Component: PMS/EAPI (show other bugs)
Hardware: All Linux
: Normal normal (vote)
Assignee: PMS/EAPI
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: future-eapi
  Show dependency tree
 
Reported: 2020-03-23 15:29 UTC by Christian Strahl
Modified: 2022-04-08 10:03 UTC (History)
3 users (show)

See Also:
Package list:
Runtime testing required: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Christian Strahl 2020-03-23 15:29:08 UTC
if I use globbing in fperms e.g.:

	src_install() {
		...
		fperms a+x /opt/${PN}/jre/bin/*
		...
	}

the globbing is resolved on the final installation path "/opt/${PN}/jre/bin/*", while fperms tries to apply the changes on the files in the sandbox, witch leads to error messages like:

chmod: cannot access '/var/tmp/portage/dev-util/smartgit-20.1.0/image/opt/smartgit/jre/bin/*': No such file or directory


Reproducible: Always
Comment 1 Mike Gilbert gentoo-dev 2020-03-23 16:30:47 UTC
This has nothing to do with the sandbox.

/opt/${PN}/jre/bin/* does not exist on your system, so the glob is not expanded.

The files should be staged in ${ED}, so you could apply the glob there instead. For example:

pushd "{ED}" || die
fperms a+x opt/${PN}/jre/bin/*
popd || die
Comment 2 Mike Gilbert gentoo-dev 2020-03-23 16:32:22 UTC
Or alternatively:

chmod a+x "${ED}"/opt/${PN}/jre/bin/*
Comment 3 Christian Strahl 2020-03-24 08:40:00 UTC
the problem from my perspective is, that fperms adds ${ED} automatically to the path, while globbing does not.

If I use
	fperms a+x /opt/${PN}/jre/bin/*
fperms uses the right directory (/${ED}), while globbing uses the wrong (/)

If I use
	fperms a+x ${ED}/opt/${PN}/jre/bin/*
fperms uses the wrong directory (/${ED}/${ED}), while globbing uses the right (/${ED})

So I cannot use fperms with globbing at all, and that was unexpected for me.

Would you prefer using chmod over fperms in that case?
Comment 4 Zac Medico gentoo-dev 2020-03-24 09:08:58 UTC
(In reply to Christian Strahl from comment #3)
> If I use
> 	fperms a+x ${ED}/opt/${PN}/jre/bin/*
> fperms uses the wrong directory (/${ED}/${ED})

I wonder if we could make this less stupid. Here's what PMS says about fperms:

> fperms
> Acts as for chmod, but takes paths relative to the image directory. Failure
> behaviour is EAPI dependent as per section 12.3.1.
Comment 5 Mike Gilbert gentoo-dev 2020-03-24 13:14:03 UTC
Sorry, your misuse of the term "sandbox" caused me to overlook what your bug report was really about.

I don't really see a simple way to improve how fperms works. I would opt to just call chmod || die directly.
Comment 6 Zac Medico gentoo-dev 2020-03-24 16:19:48 UTC
(In reply to Zac Medico from comment #4)
> (In reply to Christian Strahl from comment #3)
> > If I use
> > 	fperms a+x ${ED}/opt/${PN}/jre/bin/*
> > fperms uses the wrong directory (/${ED}/${ED})
> 
> I wonder if we could make this less stupid. Here's what PMS says about
> fperms:
> 
> > fperms
> > Acts as for chmod, but takes paths relative to the image directory. Failure
> > behaviour is EAPI dependent as per section 12.3.1.

I think the unfortunate ${ED}/${ED} behavior is required for compliance with PMS.
Comment 7 Michał Górny archtester Gentoo Infrastructure gentoo-dev Security 2020-03-24 16:28:09 UTC
(In reply to Christian Strahl from comment #3)
> the problem from my perspective is, that fperms adds ${ED} automatically to
> the path, while globbing does not.

This is not Windows.  You should know how filename expansion works in bash.

> So I cannot use fperms with globbing at all, and that was unexpected for me.
> 
> Would you prefer using chmod over fperms in that case?

Yes.
Comment 8 Christian Strahl 2020-03-24 16:41:25 UTC
(In reply to Michał Górny from comment #7)
> (In reply to Christian Strahl from comment #3)
> > the problem from my perspective is, that fperms adds ${ED} automatically to
> > the path, while globbing does not.
> 
> This is not Windows.  You should know how filename expansion works in bash.
> 

I know how filename expansion works in bash. I jus didn't know that fperms prepends ${ED} to paths.
In the same ebuild I use other commands that don't have that behavior.

e.g.:
	java-pkg_regjar ${ED}/opt/${PN}/lib/*.jar

Here I can use ${ED} in the path because java-pkg_regjar doesn't prepend ${ED} by itself.
Comment 9 Ulrich Müller gentoo-dev 2020-03-24 17:37:52 UTC
What is the goal here? Add another helper that acts like fperms, but doesn't prefix the path with ${ED}? That would just be chmod with built-in error checking. (IMHO, not worth the effort.)

Or, have fperms itself perform globbing relative to the image directory? I'd rather not open that can of worms, because globbing is a feature of the shell.
Comment 10 Ulrich Müller gentoo-dev 2021-08-31 11:18:57 UTC
(In reply to Ulrich Müller from comment #9)
> What is the goal here? Add another helper that acts like fperms, but doesn't
> prefix the path with ${ED}? That would just be chmod with built-in error
> checking. (IMHO, not worth the effort.)
> 
> Or, have fperms itself perform globbing relative to the image directory? I'd
> rather not open that can of worms, because globbing is a feature of the
> shell.

No reply. Closing.
Comment 11 Cecil Curry 2022-04-08 04:42:26 UTC
Necrobump...because I just hit this unexpected behaviour while bumping "dev-util/android-ndk". fperms() is just a poor man's "chmod" with no tangible benefit and considerable drawbacks. Let's consider dropping fperms() entirely during the next EAPI push, because it does nothing for us, obfuscates core shell fundamentals, and detracts from meaningful work elsewhere.

Let's last-rite fperms() once and for all. The '90s are calling and they want their useless shell wrappers back.
Comment 12 Michał Górny archtester Gentoo Infrastructure gentoo-dev Security 2022-04-08 07:09:38 UTC
I'm reopening for further discussion.  Let's also add fowners since that's probably the same box.
Comment 13 Ulrich Müller gentoo-dev 2022-04-08 08:38:13 UTC
It is the same for all helper commands. They all add ED to the destination path, therefore globbing in the image directory doesn't work for any of them. That is just how the shell works, and I don't see what we could do about it.
Comment 14 Ulrich Müller gentoo-dev 2022-04-08 10:03:51 UTC
(In reply to Cecil Curry from comment #11)
> fperms() is just a poor man's "chmod" with no tangible benefit and
> considerable drawbacks.

Nobody will stop you from using plain chmod as suggested in comment #1, or using fperms on the directory recursively.

But let's count how often these commands are used in the tree (simple grep, so the number may include some false positives):

  fperms:  1180
  fowners:  853
  chmod:    721
  chown:    366

Checking a few ebuilds, most of the chmod and chown calls are in src_prepare where there is no image directory (so the helpers cannot be used).

chmod and chown with globbing, in src_install:

  'chmod.*\*' matches 30 times
  'chown.*\*' matches  3 times

So usage of these commands with globbing is a corner case, and is not a good reason to remove the helper commands (which are otherwise used more often than their plain counterparts).

Closing again, as discussed in #gentoo-pms.