Opening file to write if the destination alredy exists in SafeCopy

This commit is contained in:
2025-08-10 21:15:46 -03:00
parent a76e29572b
commit 3038a0d634

View File

@@ -264,9 +264,18 @@ func SafeCopy(L *lua.LState) int {
dst, err := os.Create(newname)
if err != nil {
L.Push(lua.LFalse)
L.Push(lua.LString("[packets] copy failed\n" + err.Error()))
return 2
if !os.IsExist(err) {
dst, err = os.Open(newname)
if err != nil {
L.Push(lua.LFalse)
L.Push(lua.LString("[packets] copy failed\n" + err.Error()))
return 2
}
} else {
L.Push(lua.LFalse)
L.Push(lua.LString("[packets] copy failed\n" + err.Error()))
return 2
}
}
defer dst.Close()