{"record":{"id":"40c1a2769eddf2f3","repo":"lima-vm/lima","slug":"failed-to-rename-asif-image-from-q-to-q-w","errorCode":null,"errorMessage":"failed to rename ASIF image from %#q to %#q: %w","messagePattern":"failed to rename ASIF image from %#q to %#q: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/imgutil/nativeimgutil/asifutil/asif_darwin.go","lineNumber":30,"sourceCode":"\t\"os\"\n\t\"os/exec\"\n\t\"strconv\"\n\t\"strings\"\n\n\t\"github.com/lima-vm/lima/v2/pkg/plist\"\n)\n\n// NewASIF creates a new ASIF image file at the specified path with the given size.\nfunc NewASIF(path string, size int64) error {\n\tcreateArgs := []string{\"image\", \"create\", \"blank\", \"--fs\", \"none\", \"--format\", \"ASIF\", \"--size\", strconv.FormatInt(size, 10), path}\n\tif err := exec.CommandContext(context.Background(), \"diskutil\", createArgs...).Run(); err != nil {\n\t\treturn fmt.Errorf(\"failed to create ASIF image %#q: %w\", path, err)\n\t}\n\tif _, err := os.Stat(path); errors.Is(err, os.ErrNotExist) {\n\t\tif _, err2 := os.Stat(path + \".asif\"); !errors.Is(err2, os.ErrNotExist) {\n\t\t\t// diskutil may create the file with .asif suffix\n\t\t\tif err3 := os.Rename(path+\".asif\", path); err3 != nil {\n\t\t\t\treturn fmt.Errorf(\"failed to rename ASIF image from %#q to %#q: %w\", path+\".asif\", path, err3)\n\t\t\t}\n\t\t}\n\t}\n\treturn nil\n}\n\n// NewAttachedASIF creates a new ASIF image file at the specified path with the given size\n// and attaches it, returning the attached device path and an open file handle.\n// The caller is responsible for detaching the ASIF image device when done.\nfunc NewAttachedASIF(path string, size int64) (string, *os.File, error) {\n\tif err := NewASIF(path, size); err != nil {\n\t\treturn \"\", nil, err\n\t}\n\tattachArgs := []string{\"image\", \"attach\", \"--noMount\", path}\n\tout, err := exec.CommandContext(context.Background(), \"diskutil\", attachArgs...).Output()\n\tif err != nil {\n\t\treturn \"\", nil, fmt.Errorf(\"failed to attach ASIF image %#q: %w\", path, err)\n\t}","sourceCodeStart":12,"sourceCodeEnd":48,"githubUrl":"https://github.com/lima-vm/lima/blob/dd909d0973cd84fa35f9e1693181b4585ea616c1/pkg/imgutil/nativeimgutil/asifutil/asif_darwin.go#L12-L48","documentation":"After creating an ASIF image, NewASIF handles a diskutil quirk: some versions create the file with a `.asif` suffix appended. This error occurs when `os.Rename(path+\".asif\", path)` fails while fixing up that quirk. It wraps the OS-level rename failure.","triggerScenarios":"NewASIF ran successfully but the produced file is at `path+\".asif\"`, and the rename back to `path` fails — typically the target exists and cannot be replaced, or a permissions/volume issue prevents the move.","commonSituations":"A stale file already exists at the target path from a previous failed run; the directory is read-only; cross-volume rename restrictions; concurrent Lima operations racing on the same path.","solutions":["Delete the pre-existing conflicting file at `path` and retry","Check write permissions on the directory containing the image","Ensure no other process is concurrently creating the same image","If rename keeps failing, manually rename `path.asif` to `path` before retrying the operation"],"exampleFix":"// before\n_ = os.Remove(diskPath) // stale file blocks rename\nerr := asifutil.NewASIF(diskPath, size)\n// after\nif err := os.Remove(diskPath); err != nil && !os.IsNotExist(err) { return err }\nif err := asifutil.NewASIF(diskPath, size); err != nil { return err }","handlingStrategy":"try-catch","validationCode":"// preflight: ensure target path is free before creating the image\nif _, err := os.Stat(path); err == nil { return fmt.Errorf(\"image path %q already exists\", path) }","typeGuard":null,"tryCatchPattern":"if err := asifutil.NewASIF(path, size); err != nil {\n    if strings.Contains(err.Error(), \"failed to rename\") {\n        os.Remove(path); os.Remove(path + \".asif\") // clear stale files, then retry once\n    }\n    return err\n}","preventionTips":["Remove stale image files from previous failed runs","Avoid concurrent operations on the same image path","Create images in directories with write permission"],"tags":["macos","file-rename","disk-image","asif"],"backgroundTag":"file-rename-failed","analyzedSha":"dd909d0973cd84fa35f9e1693181b4585ea616c1","analyzedAt":"2026-09-01T14:24:59.842Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}