(baseCacheDirPath string, relDirPath string)
| 368 | } |
| 369 | |
| 370 | func createCacheDir(baseCacheDirPath string, relDirPath string) error { |
| 371 | baseCacheDirPath = normalpath.Unnormalize(baseCacheDirPath) |
| 372 | relDirPath = normalpath.Unnormalize(relDirPath) |
| 373 | fullDirPath := filepath.Join(baseCacheDirPath, relDirPath) |
| 374 | // OK to use os.Stat instead of os.LStat here as this is CLI-only |
| 375 | fileInfo, err := os.Stat(fullDirPath) |
| 376 | if err != nil { |
| 377 | if errors.Is(err, fs.ErrNotExist) { |
| 378 | return os.MkdirAll(fullDirPath, 0755) |
| 379 | } |
| 380 | return err |
| 381 | } |
| 382 | if !fileInfo.IsDir() { |
| 383 | return fmt.Errorf( |
| 384 | "Expected %q to be a directory. This is used for buf's cache. "+ |
| 385 | "You can override the base cache directory %q by setting the $BUF_CACHE_DIR environment variable.", |
| 386 | fullDirPath, |
| 387 | baseCacheDirPath, |
| 388 | ) |
| 389 | } |
| 390 | if fileInfo.Mode().Perm()&0700 != 0700 { |
| 391 | return fmt.Errorf( |
| 392 | "Expected %q to be a writeable directory. This is used for buf's cache. "+ |
| 393 | "You can override the base cache directory %q by setting the $BUF_CACHE_DIR environment variable.", |
| 394 | fullDirPath, |
| 395 | baseCacheDirPath, |
| 396 | ) |
| 397 | } |
| 398 | return nil |
| 399 | } |
no test coverage detected
searching dependent graphs…