{"record":{"id":"4256bcecba487723","repo":"hashicorp/nomad","slug":"could-not-copy-file-v","errorCode":null,"errorMessage":"could not copy file: %v","messagePattern":"could not copy file: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"helper/escapingfs/copydir.go","lineNumber":54,"sourceCode":"\n\t\tr, err := srcFs.Open(oldPath)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"could not open existing file: %v\", err)\n\t\t}\n\t\tdefer r.Close()\n\t\tinfo, err := r.Stat()\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"could not stat file: %v\", err)\n\t\t}\n\n\t\tw, err := os.OpenFile(newPath, os.O_CREATE|os.O_EXCL|os.O_WRONLY, info.Mode())\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\n\t\tif _, err := io.Copy(w, r); err != nil {\n\t\t\tw.Close()\n\t\t\treturn fmt.Errorf(\"could not copy file: %v\", err)\n\t\t}\n\t\treturn w.Close()\n\t})\n}\n","sourceCodeStart":36,"sourceCodeEnd":59,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/helper/escapingfs/copydir.go#L36-L59","documentation":"After creating the destination file, CopyDir streams the source contents with io.Copy. If reading the source or writing to the destination fails, the walk aborts with 'could not copy file: %v' wrapping the io error. This surfaces disk-full, permission, and mid-copy I/O failures.","triggerScenarios":"CopyDir where io.Copy fails: destination filesystem is full (ENOSPC), destination path permissions deny writing after open, source file read error mid-stream (NFS drop, disk error), or process resource limits.","commonSituations":"Host disk full when copying client task directories; quota-limited volumes; copy interrupted by storage failure; source on a flaky network mount; large files hitting disk quotas.","solutions":["Check free space on the destination filesystem (`df -h`) and free space or move the copy target to a volume with room","Fix destination permissions/ownership so the process can write the file contents","Check source media health and remount/retry if a network filesystem dropped","Run `dmesg`/storage diagnostics if errors persist; check quotas"],"exampleFix":"// before\n$ df -h /var/lib/nomad\n/dev/sda1  10G  10G  0  100% /var/lib/nomad\n// after\n$ rm -rf /var/lib/nomad/tmp/*   # or expand the volume\n$ df -h /var/lib/nomad\n/dev/sda1  10G  4G  6G  40% /var/lib/nomad","handlingStrategy":"validation","validationCode":"var st syscall.Statfs_t\nif err := syscall.Statfs(dstRoot, &st); err != nil { return err }\navail := int64(st.Bavail) * int64(st.Bsize)\nneeded := dirSize(src) // sum of source file sizes\nif avail < needed*2 { return fmt.Errorf(\"insufficient space: need %d, have %d\", needed*2, avail) }","typeGuard":null,"tryCatchPattern":"if err := escapingfs.CopyDir(src, dst); err != nil {\n    if strings.HasPrefix(err.Error(), \"could not copy file\") {\n        // typically ENOSPC or write failure: free space / check dest volume, then retry\n        log.Error(\"copy failed\", \"err\", err)\n        return fmt.Errorf(\"copy failed, check dest disk space: %w\", err)\n    }\n    return err\n}","preventionTips":["Check destination free space before copying (df -h or Statfs)","Watch disk quotas and retention on the destination volume","Avoid copying across flaky network mounts; stage locally first","Monitor dmesg/storage alerts on hosts performing large copies"],"tags":["filesystem","disk-full","io","copy"],"backgroundTag":"disk-full","analyzedSha":"482b49bf1aec006f089bcfc7e632d8f6ac303e5e","analyzedAt":"2026-09-04T07:54:14.808Z","contentChangedAt":"2026-09-04T07:54:14.808Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}