Why does Bitbucket occasionally not remove the directory from the filesystem when a repository is deleted?

Still need help?

The Atlassian Community is here for you.

Ask the community


Platform notice: Server and Data Center only. This article only applies to Atlassian products on the Server and Data Center platforms.

Support for Server* products ended on February 15th 2024. If you are running a Server product, you can visit the Atlassian Server end of support announcement to review your migration options.

*Except Fisheye and Crucible

 

Summary

When a repository is deleted from Bitbucket the on disk directory and files are also expected to be removed:

$BITBUCKET_HOME/shared/data/repositories/<RepoID>

It is occasionally noted that although the repository has been removed from Bitbucket and database, the directory remains and a "DELETED" file is placed in the directory.

Why is the directory not removed?

When a parent repository of forked repos is deleted while the child repositories are still present, Bitbucket creates a "DELETED" file inside the repository instead of actually deleting it from filesystem. Bitbucket implements forking by having the child repository. This is because the child forks are still referencing the objects from this repository on the filesystem. Deleting this from filesystem will make the child forks unusable.

How does Bitbucket consider a repository with a DELETED in its directory?

Bitbucket has no reference for this repository in its database and from the perspective of Bitbucket this repository does not exist, hence Bitbucket will allow you to create new repository with same name. However in the backend filesystem the forked repositories might still be referencing objects from the parent repository directory, hence it is not deleted from filesystem.

Solution

Should we manually remove the directory?

Unfortunately Bitbucket does not remove these repositories from filesystem even after all the forks are deleted. Since the repository is already deleted from Bitbucket database, it has no way of tracking them.

We have raised a Feature Request to avoid these issues by notifying the user about existing forks before the deletion:

If you absolutely need to delete these repositories, currently the only way is to do it manually. In order to manually delete them, first you need to be sure there are no forks referencing objects from them.

How to find which repositories refer to the deleted repository?

Since the repository is removed from the UI, one way to do this is to scan contents of all 'alternates' files inside all repositories to see if any one references to the current repository directory.

The following commands will check the alternates files of all the repositories and return the list of alternates that have a reference to <RepoID>.

$ cd $BITBUCKET_HOME/shared/data/repositories/
$ grep -iRl "repositories/<RepoID>" */objects/info/alternates
Last modified on May 2, 2023

Was this helpful?

Yes
No
Provide feedback about this article
Powered by Confluence and Scroll Viewport.