Commit Graph

3 Commits

Author SHA1 Message Date
Doug Rabson a603753982 pkg/fileutils: fix Lexists on FreeBSD
The faccessat system call does not support AT_SYMLINK_NOFOLLOW on
FreeBSD versions before 15.0. This works around the limitation by
falling back to os.Lstat if faccessat returns an EINVAL error.

Signed-off-by: Doug Rabson <dfr@rabson.org>
2024-08-21 15:25:07 +01:00
Giuseppe Scrivano 543bba0b05
fileutils: make (Le|E)xists return os.PathError
wrap the returned error in a os.PathError so the error includes the
file path.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2024-04-10 10:56:55 +02:00
Giuseppe Scrivano 336611b4d0
fileutils: new functions to check for path existence
On unix they use the access syscall which is faster than stat for
simply checking the existence of a file.

with a file in the cache I see on my machine:

$ go test -bench=.
goos: linux
goarch: amd64
pkg: github.com/containers/storage/pkg/fileutils
cpu: Intel(R) Core(TM) i7-10850H CPU @ 2.70GHz
BenchmarkExists-12    	  925832	      1245 ns/op
BenchmarkStat-12      	  745896	      1602 ns/op
PASS

I'd expect even better results if the file is not already in the cache.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2024-04-08 16:07:26 +02:00