Files
NanoKVM-MIRROR/server/utils/move_file.go
wj-xiao 0e30a26db4 Streaming Refactor:
- H.264 WebRTC: Refactored to significantly reduce video latency
- H.264 Direct: Optimized data transmission; data parsing now continues correctly even when the tab is in the background
- MJPEG: Refactored to ensure the correct data length is sent

Bug Fixes
- Fixed an issue where certain keyboard modifier keys were not recognized
- Fixed vertical mouse cursor drift when the page is zoomed in or out

Optimizations
- Optimized HID write logic and updated the HID reset mechanism
- Added support for deleting images
- Added a Swap Memory option to the Tailscale page
- Added a confirmation dialog when uninstalling Tailscale to prevent accidental removal
- Improved the logic for updating the web page title
- Improved the UI for the Clipboard, Settings, Image Mounting, and App Update pages

Security
- Added a mandatory delay after failed login attempts to prevent brute-force attacks
- Updated dependencies to patch known security vulnerabilities
2025-11-26 10:57:30 +08:00

79 lines
1.4 KiB
Go

package utils
import (
"io"
"os"
"path/filepath"
"strings"
)
func MoveFile(src, dst string) error {
if err := os.MkdirAll(filepath.Dir(dst), 0o755); err != nil {
return err
}
err := os.Rename(src, dst)
if err != nil {
if strings.Contains(err.Error(), "invalid cross-device link") {
return MoveFileCrossFS(src, dst)
}
return err
}
return nil
}
func MoveFileCrossFS(src, dst string) error {
tmp := dst + ".tmp"
srcFile, err := os.Open(src)
if err != nil {
return err
}
tmpFile, err := os.Create(tmp)
if err != nil {
_ = srcFile.Close()
return err
}
_, err = io.Copy(tmpFile, srcFile)
if err != nil {
_ = srcFile.Close()
_ = tmpFile.Close()
return err
}
_ = srcFile.Close()
_ = tmpFile.Close()
fi, err := os.Stat(src)
if err != nil {
return err
}
err = os.Chmod(tmp, fi.Mode())
if err != nil {
return err
}
_ = os.Remove(src)
err = os.Rename(tmp, dst)
if err != nil {
return err
}
return nil
}
func MoveFilesRecursively(src, dst string) error {
return filepath.Walk(src, func(path string, info os.FileInfo, err error) error {
if err != nil {
return err
}
fileName := strings.Replace(path, src, "", 1)
dstName := dst + fileName
fileInfo, err := os.Stat(path)
if err != nil {
return err
}
if fileInfo.IsDir() {
return os.MkdirAll(dstName, fileInfo.Mode())
}
return MoveFile(path, dstName)
})
}