gitea icon indicating copy to clipboard operation
gitea copied to clipboard

Template repo files should be cleaned up after an error

Open jtran opened this issue 2 years ago • 1 comments

Description

Steps to reproduce:

  1. Create a repo from a template repo
  2. Create fails due to some reason (repo-avatar file not found, in my case)
  3. 500 error
  4. Go back in the browser to the new repository form
  5. Try to create an empty repo with the same name and owner (without the problematic template)

I expected the creation of an empty repo to work for a repo name that isn't used. However, the repo creation fails with an error message:

Files already exist for this repository. Contact the system administrator.

To fix it, the admin needs to delete the bare git repo from the filesystem using rm -r. This makes the repo name available again.

In this case, one cause is the original file not found. However, filesystem changes like creating the bare git repo should get reverted in the case of an error, the same way that database changes are reverted using a transaction.

Here is the database transaction that reverts db changes. As far as I know, there is no equivalent clean-up for the filesystem.

https://github.com/go-gitea/gitea/blob/0c72256ab4e6e6f6c6cd6d4949b37d32a7816785/services/repository/template.go#L74

Contrast this with CreateRepositoryDirectly() (not from a repo template), which cleans up.

https://github.com/go-gitea/gitea/blob/0c72256ab4e6e6f6c6cd6d4949b37d32a7816785/services/repository/create.go#L304-L306

However, it's unclear to me that the above code calling DeleteRepositoryDirectly() (first introduced in #14384) actually cleans up the files because it first looks for the repo in the database, and if it's not there, returns early. At the point it's being called, the repo wouldn't be in the database because the transaction has been rolled back.

Gitea Version

1.20.5

Can you reproduce the bug on the Gitea demo site?

No

Log Gist

No response

Screenshots

No response

Git Version

No response

Operating System

Linux

How are you running Gitea?

docker

Database

PostgreSQL

jtran avatar Nov 21 '23 00:11 jtran

Encountered this yesterday, glad to see someone already reported it! And thanks for the fix.

disciple-dev avatar May 15 '24 21:05 disciple-dev