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

create cache directory if it doesn't exist #54

Merged
merged 1 commit into from
Dec 18, 2024
Merged
Changes from all commits
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
9 changes: 7 additions & 2 deletions cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,14 @@ func (d *fronted) initCaching(cacheFile string) {

func (d *fronted) prepopulateFronts(cacheFile string) {
bytes, err := os.ReadFile(cacheFile)
if os.IsNotExist(err) {
if err = os.MkdirAll(filepath.Dir(cacheFile), 0755); err != nil {
log.Errorf("Error creating cache directory: %v", err)
return
}
}
if err != nil {
// This is not a big deal since we'll just fill the cache later
log.Debugf("ignorable error: Unable to read cache file for prepopulation: %v", err)
Comment on lines -18 to -19
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think this is ignorable. By this point if it can't read the file it won't be able to write to it later.

Copy link
Contributor

Choose a reason for hiding this comment

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

This isn't really true, as it just means no cache file has been created yet. That will be true every time on the first run, for example.

Copy link
Contributor Author

@garmr-ulfr garmr-ulfr Dec 18, 2024

Choose a reason for hiding this comment

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

By this point if it can't read the file it won't be able to write to it later.

Sorry, by this I meant after including the change to create the parent directory.

However, even before this, while unlikely, it could still fail if it doesn't have read/write permissions on the directory.

log.Errorf("Error reading cache file: %v", err)
return
}

Expand Down
Loading