8000 feat: clean stale provisioner files by mtojek · Pull Request #9545 · coder/coder · GitHub
[go: up one dir, main page]

Skip to content

feat: clean stale provisioner files #9545

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

Merged
merged 27 commits into from
Sep 11, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
make fmt
  • Loading branch information
mtojek committed Sep 7, 2023
commit b273cbf0505efe7aeff5175a9593c5bd91a90153
2 changes: 1 addition & 1 deletion provisioner/terraform/cleanup.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ func latestAccessTime(fs afero.Fs, pluginPath string) (time.Time, error) {
return err
}

var accessTime = info.ModTime() // fallback to modTime if accessTime is not available (afero)
accessTime := info.ModTime() // fallback to modTime if accessTime is not available (afero)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just be aware that modtime is not guaranteed (see: https://www.kernel.org/doc/html/latest/filesystems/api-summary.html?highlight=nocmtime#c.file_update_time)

Howver, I would assume it to at least be the time the file was created.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that is correct. I was thinking about running a self-test on the cache directory, but on the other hand I wouldn't like to overcomplicate things.

if info.Sys() != nil {
timeSpec := times.Get(info)
accessTime = timeSpec.AccessTime()
Expand Down
8 changes: 4 additions & 4 deletions provisioner/terraform/cleanup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,21 +121,21 @@ func TestPluginCache_Golden(t *testing.T) {
}

func addPluginFile(t *testing.T, fs afero.Fs, pluginPath string, resourcePath string, accessTime time.Time) {
err := fs.MkdirAll(filepath.Join(cachePath, pluginPath), 0755)
err := fs.MkdirAll(filepath.Join(cachePath, pluginPath), 0o755)
require.NoError(t, err, "can't create test folder for plugin file")

err = fs.Chtimes(filepath.Join(cachePath, pluginPath), accessTime, accessTime)
require.NoError(t, err, "can't set times")

err = afero.WriteFile(fs, filepath.Join(cachePath, pluginPath, resourcePath), []byte("foo"), 0644)
err = afero.WriteFile(fs, filepath.Join(cachePath, pluginPath, resourcePath), []byte("foo"), 0o644)
require.NoError(t, err, "can't create test file")

err = fs.Chtimes(filepath.Join(cachePath, pluginPath, resourcePath), accessTime, accessTime)
require.NoError(t, err, "can't set times")
}

func addPluginFolder(t *testing.T, fs afero.Fs, pluginPath string, folderPath string, accessTime time.Time) {
err := fs.MkdirAll(filepath.Join(cachePath, pluginPath, folderPath), 0755)
err := fs.MkdirAll(filepath.Join(cachePath, pluginPath, folderPath), 0o755)
require.NoError(t, err, "can't create plugin folder")

err = fs.Chtimes(filepath.Join(cachePath, pluginPath, folderPath), accessTime, accessTime)
Expand All @@ -151,7 +151,7 @@ func diffFileSystem(t *testing.T, fs afero.Fs) {
err := os.MkdirAll(filepath.Dir(goldenFile), 0o755)
require.NoError(t, err, "want no error creating golden file directory")

err = os.WriteFile(goldenFile, actual, 0600)
err = os.WriteFile(goldenFile, actual, 0o600)
require.NoError(t, err, "want no error creating golden file")
return
}
Expand Down
2 changes: 1 addition & 1 deletion provisionersdk/cleanup.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func CleanStaleSessions(ctx context.Context, workDirectory string, fs afero.Fs,
if fi.IsDir() && isValidSessionDir(dirName) {
sessionDirPath := filepath.Join(workDirectory, dirName)

var accessTime = fi.ModTime() // fallback to modTime if accessTime is not available (afero)
accessTime := fi.ModTime() // fallback to modTime if accessTime is not available (afero)
if fi.Sys() != nil {
timeSpec := times.Get(fi)
accessTime = timeSpec.AccessTime()
Expand Down
2 changes: 1 addition & 1 deletion provisionersdk/cleanup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func TestStaleSessions(t *testing.T) {
}

func addSessionFolder(t *testing.T, fs afero.Fs, sessionName string, accessTime time.Time) {
err := fs.MkdirAll(filepath.Join(workDirectory, sessionName), 0755)
err := fs.MkdirAll(filepath.Join(workDirectory, sessionName), 0o755)
require.NoError(t, err, "can't create session folder")
fs.Chtimes(filepath.Join(workDirectory, sessionName), accessTime, accessTime)
require.NoError(t, err, "can't set times")
Expand Down
0