remove upload: remove #6336

Closed
opened 2025-11-02 06:53:01 -06:00 by GiteaMirror · 5 comments
Owner

Originally created by @aszswaz on GitHub (Nov 18, 2020).

When using the file upload function of gitea, an error occurred. How can I solve this? Going back to the warehouse page, you can see that the file upload was successful, but the upload cache file deletion failed.
The error message is:
remove upload: remove C:/Program Files/gitea/data/tmp/uploads/a/d/ad727a50-7d9d-4ae4-bcef-25f4e58fd2d6: The process cannot access the file because it is being used by another process.

Originally created by @aszswaz on GitHub (Nov 18, 2020). When using the file upload function of gitea, an error occurred. How can I solve this? Going back to the warehouse page, you can see that the file upload was successful, but the upload cache file deletion failed. The error message is: remove upload: remove C:/Program Files/gitea/data/tmp/uploads/a/d/ad727a50-7d9d-4ae4-bcef-25f4e58fd2d6: The process cannot access the file because it is being used by another process.
GiteaMirror added the type/bug label 2025-11-02 06:53:01 -06:00
Author
Owner

@lunny commented on GitHub (Nov 18, 2020):

It seems it's a bug. The file point isn't closed.

@lunny commented on GitHub (Nov 18, 2020): It seems it's a bug. The file point isn't closed.
Author
Owner

@aszswaz commented on GitHub (Nov 20, 2020):

It seems it's a bug. The file point isn't closed.

Thanks for the answer, that is to say, this bug cannot be solved by modifying the configuration file?

@aszswaz commented on GitHub (Nov 20, 2020): > It seems it's a bug. The file point isn't closed. Thanks for the answer, that is to say, this bug cannot be solved by modifying the configuration file?
Author
Owner

@6543 commented on GitHub (Nov 24, 2020):

@aszswaz it would be nice if you can add some information about your gitea.

  • version
  • dbms
  • os = windows10?
  • logs?
@6543 commented on GitHub (Nov 24, 2020): @aszswaz it would be nice if you can add some information about your gitea. - version - dbms - os = windows10? - logs?
Author
Owner

@garfeng commented on GitHub (Mar 19, 2021):

上传文件至 '' 时发生错误:remove upload: remove G:/tmp/gitea-1.13.4-windows-4.0-amd64.exe/data/tmp/uploads/4/f/4f13785e-3e6a-4539-8714-ef3bae1c4ed8: The process cannot access the file because it is being used by another process.

log:

2021/03/19 13:06:34 ...uters/repo/editor.go:698:UploadFilePost() [E] Error during upload to repo: 1:garfeng/first to filepath:  on master from garfeng-patch-1: remove upload: remove G:/tmp/gitea-1.13.4-windows-4.0-amd64.exe/data/tmp/uploads/4/f/4f13785e-3e6a-4539-8714-ef3bae1c4ed8: The process cannot access the file because it is being used by another process.

os is win10

@6543

@garfeng commented on GitHub (Mar 19, 2021): ``` 上传文件至 '' 时发生错误:remove upload: remove G:/tmp/gitea-1.13.4-windows-4.0-amd64.exe/data/tmp/uploads/4/f/4f13785e-3e6a-4539-8714-ef3bae1c4ed8: The process cannot access the file because it is being used by another process. ``` log: ``` 2021/03/19 13:06:34 ...uters/repo/editor.go:698:UploadFilePost() [E] Error during upload to repo: 1:garfeng/first to filepath: on master from garfeng-patch-1: remove upload: remove G:/tmp/gitea-1.13.4-windows-4.0-amd64.exe/data/tmp/uploads/4/f/4f13785e-3e6a-4539-8714-ef3bae1c4ed8: The process cannot access the file because it is being used by another process. ``` os is win10 @6543
Author
Owner

@garfeng commented on GitHub (Mar 19, 2021):

The bug is here.

// UploadRepoFiles uploads files to the given repository
func UploadRepoFiles(repo *models.Repository, doer *models.User, opts *UploadRepoFileOptions) error {
	...
	for i, uploadInfo := range infos {
		file, err := os.Open(uploadInfo.upload.LocalPath()) 
		if err != nil {
			return err
		}
		defer file.Close() // bug !!
		...
	}
	...
	return return models.DeleteUploads(uploads...) // the file handles are still not closed yet
}

Please do like this:

// UploadRepoFiles uploads files to the given repository
func UploadRepoFiles(repo *models.Repository, doer *models.User, opts *UploadRepoFileOptions) error {
	for i, uploadInfo := range infos {
		func() {
			file, err := os.Open(uploadInfo.upload.LocalPath())
			if err != nil {
				return err
			}
			defer file.Close() // the file handle will be closed when the anonymous func return
			...
		}()
		
	}
	...
	return return models.DeleteUploads(uploads...)
}

@6543

@garfeng commented on GitHub (Mar 19, 2021): ### The bug is here. ``` go // UploadRepoFiles uploads files to the given repository func UploadRepoFiles(repo *models.Repository, doer *models.User, opts *UploadRepoFileOptions) error { ... for i, uploadInfo := range infos { file, err := os.Open(uploadInfo.upload.LocalPath()) if err != nil { return err } defer file.Close() // bug !! ... } ... return return models.DeleteUploads(uploads...) // the file handles are still not closed yet } ``` ### Please do like this: ``` go // UploadRepoFiles uploads files to the given repository func UploadRepoFiles(repo *models.Repository, doer *models.User, opts *UploadRepoFileOptions) error { for i, uploadInfo := range infos { func() { file, err := os.Open(uploadInfo.upload.LocalPath()) if err != nil { return err } defer file.Close() // the file handle will be closed when the anonymous func return ... }() } ... return return models.DeleteUploads(uploads...) } ``` @6543
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/gitea#6336