-
Notifications
You must be signed in to change notification settings - Fork 1
Replace os
filesystem operations with pkg/filesystem
#22
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
Conversation
os
file operations with pkg/filesystem
os
filesystem operations with pkg/filesystem
1b29556
to
426b71f
Compare
3d92ec1
to
48336bc
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, I skimmed through the PR, and compared umasks.
Side note: as we own the repository, could we remove the vendor
dir?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 Nice work!
) | ||
|
||
// FS is the default filesystem used by the package. | ||
var FS vfs.FS = vfs.OSFS |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we protect this with a mutex?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could, but swapping out the filesystem after the lib has been used is a bit iffy. Would result in an inconsistent filesystem. 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm going to merge it like this for now, let's add it if we find a use-case 👍🏻. Most operations would need to change from filesystem.FS
to filesystem.FS()
though so it would mean another commit with many changes, unfortunately.
pkg/snapshot/snapshot.go
Outdated
_, _, errno := syscall.Syscall(unix.SYS_SYNCFS, dir.Fd(), 0, 0) | ||
d, ok := dir.(*os.File) | ||
if !ok { | ||
return nil, nil, errors.New("unable to convert directory to file") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it make more sense here to call sync on filepath.Dir(dir)
instead of erroring?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need the file descriptor (.Fd()
) for the sycall, so there's nothing we can do if this fails.
We could do an interface test for Fd() uintptr
instead though as it's more flexible.
@mtojek I'll make a separate PR for that 👍🏻 |
This PR replaces most
os
filesystem operations withvfs.FS
invoked viapkg/filesystem
.Part of coder/envbuilder#230.
This allows us to run Kaniko (ish) safely with read-only or memory filesystems. It also allows us to transparently decompress cache archives to support multi-stage build cache probing.
Kaniko still calls out to a few libraries (e.g.
godirwalk
,otiai10/copy
, etc.) that don't support swapping outos
. That's not something we have to deal with for cache probing so it's not a high priority.For simplicity,
filesystem.CreateTemp
andfilesystem.MkdirTemp
just call out to theiros
equivalents for simplicity but kept in thefilesystem
package for consistency (os
write operations).Note: Initially this PR used afero, but afero was replaced due to inconsistency with stdlib functions (e.g.
afero.Walk
!=filepath.Walk
) and convoluted API ((afero.Lstater).LstatIfPossible
, among other).