spf13 / afero

A FileSystem Abstraction System for Go
Apache License 2.0
5.8k stars 498 forks source link

[RFC] add Lchown #342

Closed jxsl13 closed 6 months ago

jxsl13 commented 2 years ago

Changing the owner of symlinks seems pretty useful to me.

I'd suggest the following method signature, same as LstatIfPossible.

type LinkOwner interface {
    LchownIfPossible(path string, uid, gid int) (bool, error)
}

The bool return value is true in case Lchown was used and false otherwise This interface will most likely somehow require the Lstater interface to be implemented as well, as it's easiest to check whether the target path is a symlink and then decide based on that information whethe rto use LchownIfPossible or simply Chown

The Lstater interface implementation is not necessary for the OsFs but might be useful for other purposes down the line.

My use case is:

Discussion topics:

Looking at the other symlink related methods, the following interface seems to be the better option in addition to a custom PathError that is returned in case that the underlying implementation does not support this interface.

type LinkOwner interface {
    LchownIfPossible(path string, uid, gid int) error
}