Removing and writing again if the newpath alredy exists while moving, copying and doing symbolic links

This commit is contained in:
2025-08-10 12:48:48 -03:00
parent bb3ef5bb63
commit b0c29ee552

View File

@@ -220,6 +220,9 @@ func SafeRename(L *lua.LState) int {
return 2
}
if _, err := os.Stat(newname); err == nil {
os.RemoveAll(newname)
}
if err := os.Rename(oldname, newname); err != nil {
L.Push(lua.LFalse)
L.Push(lua.LString("[packets] rename failed\n" + err.Error()))
@@ -262,6 +265,10 @@ func SafeCopy(L *lua.LState) int {
return 2
}
if _, err := os.Stat(newname); err == nil {
os.RemoveAll(newname)
}
dst, err := os.Create(newname)
if err != nil {
L.Push(lua.LFalse)
@@ -298,6 +305,10 @@ func SymbolicLua(L *lua.LState) int {
return 2
}
if _, err := os.Stat(destination); err == nil {
os.RemoveAll(destination)
}
if err := os.Symlink(fileName, destination); err != nil {
L.Push(lua.LFalse)
L.Push(lua.LString("[packets] symlink failed\n" + err.Error()))