Skip to content

Commit 7fbb1af

Browse files
committed
fix: safely abort config file write
1 parent 76b6285 commit 7fbb1af

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

ipfs-9-to-10/migration/config_conv.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,22 @@ func convertFile(path string, enableQuic bool, convBootstrap convArray, convSwar
2929
}
3030
defer in.Close()
3131

32+
// Create a temp file to write the output to on success
3233
out, err := atomicfile.New(path, 0660)
3334
if err != nil {
3435
return err
3536
}
36-
defer out.Close()
3737

38-
return convert(in, out, enableQuic, convBootstrap, convSwarm)
38+
err = convert(in, out, enableQuic, convBootstrap, convSwarm)
39+
if err != nil {
40+
// There was an error so abort writing the output and clean up temp file
41+
out.Abort()
42+
} else {
43+
// Write the output and clean up temp file
44+
out.Close()
45+
}
46+
47+
return err
3948
}
4049

4150
// convert converts the config from one version to another

0 commit comments

Comments
 (0)