{"record":{"id":"19347bc813efa138","repo":"kubernetes/kops","slug":"error-creating-directories-q-v","errorCode":null,"errorMessage":"error creating directories %q: %v","messagePattern":"error creating directories %q: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"upup/pkg/fi/assetstore.go","lineNumber":307,"sourceCode":"\t\terr = a.addArchive(source, localFile)\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\t}\n\n\treturn nil\n}\n\nfunc (a *AssetStore) addArchive(archiveSource *Source, archiveFile string) error {\n\textracted := path.Join(a.cacheDir, \"extracted/\"+path.Base(archiveFile))\n\n\tif _, err := os.Stat(extracted); os.IsNotExist(err) {\n\t\t// We extract to a temporary dir which we then rename so this is atomic\n\t\t// (untarring can be slow, and we might crash / be interrupted half-way through)\n\t\textractedTemp := extracted + \".tmp-\" + strconv.FormatInt(time.Now().UnixNano(), 10)\n\t\terr := os.MkdirAll(extractedTemp, 0o755)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"error creating directories %q: %v\", path.Dir(extractedTemp), err)\n\t\t}\n\n\t\targs := []string{\"tar\", \"zxf\", archiveFile, \"-C\", extractedTemp}\n\t\tklog.Infof(\"running extract command %s\", args)\n\t\tcmd := exec.Command(args[0], args[1:]...)\n\t\toutput, err := cmd.CombinedOutput()\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"error expanding asset file %q %v: %s\", archiveFile, err, string(output))\n\t\t}\n\n\t\tif err := os.Rename(extractedTemp, extracted); err != nil {\n\t\t\treturn fmt.Errorf(\"error renaming extracted temp dir %s -> %s: %v\", extractedTemp, extracted, err)\n\t\t}\n\t}\n\n\tlocalBase := extracted\n\tassetBase := \"\"\n","sourceCodeStart":289,"sourceCodeEnd":325,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/upup/pkg/fi/assetstore.go#L289-L325","documentation":"kOps's asset store extracts downloaded archives into a directory, but to make the extraction atomic it first extracts into a temporary '.tmp-<timestamp>' directory created with os.MkdirAll. When MkdirAll cannot create that directory (permissions, disk full, path issues), addArchive returns 'error creating directories %q: %v' wrapping the underlying OS error with the parent path of the temp dir.","triggerScenarios":"addURLs -> addArchive where the extracted asset directory does not exist yet and os.MkdirAll on '<extracted>.tmp-<nanotimestamp>' fails — e.g. read-only parent, EACCES, ENOSPC, or a path component is a file.","commonSituations":"Running kOps as non-root against asset dirs owned by root; disk quota/full on the state store working volume; SELinux/AppArmor blocking writes in the working directory; a stale file occupying a path component of the extraction dir.","solutions":["Inspect the wrapped %v OS error to identify the failing path and errno (EACCES/ENOSPC/ENOTDIR).","Fix filesystem permissions or free disk space on the volume holding the asset store working directory.","Remove stale files/dirs at the extraction path so MkdirAll can create parents.","Re-run the command as a user with write access to the working directory.","Retry after clearing any transient condition; the temp dir is unique per nanotimestamp so retries won't collide."],"exampleFix":"// diagnose the wrapped cause instead of only the wrapper\nif _, err := os.Stat(extracted); os.IsNotExist(err) {\n  extractedTemp := extracted + \".tmp-\" + strconv.FormatInt(time.Now().UnixNano(), 10)\n  if err := os.MkdirAll(extractedTemp, 0o755); err != nil {\n    klog.Warningf(\"MkdirAll failed for %s: %v\", extractedTemp, err)\n    return fmt.Errorf(\"error creating directories %q: %v\", path.Dir(extractedTemp), err)\n  }\n}","handlingStrategy":"validation","validationCode":"const extracted = \"/var/cache/kops/assets/nodeup\"\nconst extractedTemp = extracted + \".tmp-\" + Date.now()\nimport fs from \"fs\"\n// pre-check writability of the parent dir\nfs.accessSync(require(\"path\").dirname(extractedTemp), fs.constants.W_OK)\nif (fs.existsSync(extracted)) throw new Error(\"already extracted: \" + extracted)","typeGuard":"function isNil<T>(v: T | null | undefined): v is null | undefined { return v === null || v === undefined }","tryCatchPattern":"try {\n  await addURLs(urls)\n} catch (e) {\n  if (/error creating directories/.test(e.message)) {\n    // inspect wrapped cause, fix perms/space, retry once\n    console.error(\"asset dir unwritable:\", e.message)\n  }\n  throw e\n}","preventionTips":["Run kOps as a user with write access to the asset working directory.","Monitor disk space/quota on the state store volume.","Avoid sharing one asset store dir between concurrent processes.","Check for files squatting the extraction path after interrupted runs."],"tags":["filesystem","assets","io"],"backgroundTag":"mkdir-permission-denied","analyzedSha":"4c8573c808a73d578c5eadc86d410646ea0b0d73","analyzedAt":"2026-09-05T04:13:19.212Z","contentChangedAt":"2026-09-05T04:13:19.212Z","schemaVersion":2},"datasetVersion":"2026-09-12T07:17:12.445Z"}