Skip to content
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

Check file hashes and permissions on non-0 Legacy CLI exit code #92

Open
akalipetis opened this issue Jul 31, 2023 · 1 comment
Open

Comments

@akalipetis
Copy link
Member

akalipetis commented Jul 31, 2023

When running the Legacy CLI and there is a non-zero exit code, we should check file hashes and permissions and if needed cleanup the cache directory.

Tasks

No tasks being tracked yet.
@pjcdawkins
Copy link
Contributor

Or something like this - we already call os.Stat() to check for existence - so this adds the size check and then the comparison, currently byte-by-byte. It would be more memory-efficient (not necessarily faster) if we compare hashes - dynamically calculated, or perhaps statically embedded in the Go binary and statically written in the cache directory. Given the files add up to ~20MB we'd probably want hashes.

// fileChanged checks if a file's content differs from the provided bytes.
func fileChanged(filename string, content []byte) (bool, error) {
	stat, err := os.Stat(filename)
	if err != nil {
		if os.IsNotExist(err) {
			return true, nil
		}
		return false, fmt.Errorf("could not stat file: %w", err)
	}
	if int(stat.Size()) != len(content) {
		return true, nil
	}
	current, err := os.ReadFile(filename)
	if err != nil {
		return false, err
	}
	return !bytes.Equal(current, content), nil
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants