Skip to content
This repository has been archived by the owner on Nov 17, 2021. It is now read-only.

Implement local file cache for HTTP URLs #309

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

tinyzimmer
Copy link

This PR implements a dumb local cache for files fetched remotely. Cache location defaults to <user_cache_dir>/kubecfg. Files are written to subdirectories matching the "path" fields in the URL.

The location of the cache is configurable with the --cache-dir flag.

@tinyzimmer tinyzimmer changed the title implement local file cache for HTTP URLs Implement local file cache for HTTP URLs Jun 5, 2021
}
}

var httpRegex = regexp.MustCompile("^(https?)://")
Copy link
Author

Choose a reason for hiding this comment

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

I was originally going to just escape the // - hence the capture group.

Ultimately, liked just stripping the protocol and nesting directories more. Makes for an easier to manage cache as well imo.

if err == nil && !finfo.IsDir() {
return fmt.Errorf("%q is not a directory, it cannot be used for caching", localPathDir)
}
return ioutil.WriteFile(localPath, contents, 0644)
Copy link
Author

Choose a reason for hiding this comment

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

I don't know off hand if this will replace an existing symlink to nothing (the afore discussed power-user way of disabling caching for certain things) or return an error. I should test it probably before this is merged. ​I assume if it doesn't error, we'll want to check for a pre-existing dead link or whatever to make sure we don't mess with something the user did on purpose.

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

Successfully merging this pull request may close these issues.

None yet

1 participant