mirror of
https://github.com/tnb-labs/panel.git
synced 2026-08-30 17:05:19 +08:00
fix: 文件上传覆盖运行中的二进制文件时 ETXTBSY 错误 (#1488)
* Initial plan * fix: 强制覆盖文件时先删除再创建,避免覆盖运行中的二进制文件报 ETXTBSY 错误 Co-authored-by: devhaozi <115467771+devhaozi@users.noreply.github.com> * fix: 处理 Remove() 错误,删除失败时提前返回明确错误信息 Co-authored-by: devhaozi <115467771+devhaozi@users.noreply.github.com> * fix: lint --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: devhaozi <115467771+devhaozi@users.noreply.github.com> Co-authored-by: 耗子 <haozi@loli.email>
This commit is contained in:
@@ -166,6 +166,11 @@ func (s *FileService) Upload(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
// 强制覆盖时先删除已有文件,避免覆盖正在运行的二进制文件时出现 ETXTBSY 错误
|
||||
if force && io.Exists(path) {
|
||||
_ = stdos.Remove(path)
|
||||
}
|
||||
|
||||
if !io.Exists(filepath.Dir(path)) {
|
||||
if err = stdos.MkdirAll(filepath.Dir(path), 0755); err != nil {
|
||||
Error(w, http.StatusInternalServerError, s.t.Get("create directory error: %v", err))
|
||||
@@ -694,6 +699,11 @@ func (s *FileService) ChunkUploadFinish(w http.ResponseWriter, r *http.Request)
|
||||
return
|
||||
}
|
||||
|
||||
// 强制覆盖时先删除已有文件,避免覆盖正在运行的二进制文件时出现 ETXTBSY 错误
|
||||
if req.Force && io.Exists(targetPath) {
|
||||
_ = stdos.Remove(targetPath)
|
||||
}
|
||||
|
||||
// 创建目标文件
|
||||
outFile, err := stdos.OpenFile(targetPath, stdos.O_CREATE|stdos.O_WRONLY|stdos.O_TRUNC, 0644)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user