cache: Simplify cache dir creation

This commit is contained in:
Alexander Neumann
2017-11-20 21:58:38 +01:00
parent fa893ee477
commit f4bab789b8
2 changed files with 22 additions and 23 deletions

View File

@@ -85,10 +85,12 @@ func writeCachedirTag(dir string) error {
// performReadahead returns true.
func New(id string, basedir string) (c *Cache, err error) {
if basedir == "" {
basedir, err = defaultCacheDir()
if err != nil {
return nil, err
}
basedir, err = DefaultDir()
}
err = mkdirCacheDir(basedir)
if err != nil {
return nil, err
}
// create base dir and tag it as a cache directory
@@ -108,13 +110,14 @@ func New(id string, basedir string) (c *Cache, err error) {
return nil, errors.New("cache version is newer")
}
err = updateTimestamp(cachedir)
if err != nil {
// create the repo cache dir if it does not exist yet
if err = fs.MkdirAll(cachedir, dirMode); err != nil {
return nil, err
}
// create the repo cache dir if it does not exist yet
if err = fs.MkdirAll(cachedir, dirMode); err != nil {
// update the timestamp so that we can detect old cache dirs
err = updateTimestamp(cachedir)
if err != nil {
return nil, err
}