Template repo files should be cleaned up after an error #12055

Closed
opened 2025-11-02 09:56:19 -06:00 by GiteaMirror · 2 comments
Owner

Originally created by @jtran on GitHub (Nov 21, 2023).

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.

0c72256ab4/services/repository/template.go (L74)

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

0c72256ab4/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

Originally created by @jtran on GitHub (Nov 21, 2023). ### 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
GiteaMirror added the issue/criticaltype/bug labels 2025-11-02 09:56:20 -06:00
Author
Owner

@disciple-dev commented on GitHub (May 15, 2024):

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

@disciple-dev commented on GitHub (May 15, 2024): Encountered this yesterday, glad to see someone already reported it! And thanks for the fix.
Author
Owner

@lunny commented on GitHub (Mar 27, 2025):

I sent #31035, could you help to review it? @jtran

@lunny commented on GitHub (Mar 27, 2025): I sent #31035, could you help to review it? @jtran
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/gitea#12055