mirror of
https://github.com/gitbucket/gitbucket.git
synced 2026-01-05 07:09:56 +01:00
(refs #1631)Copy repository files directory only if it exists
This commit is contained in:
@@ -598,18 +598,19 @@ trait AccountControllerBase extends AccountManagementControllerBase {
|
||||
// clone repository actually
|
||||
JGitUtil.cloneRepository(
|
||||
getRepositoryDir(repository.owner, repository.name),
|
||||
getRepositoryDir(accountName, repository.name))
|
||||
FileUtil.deleteIfExists(getRepositoryDir(accountName, repository.name)))
|
||||
|
||||
// Create Wiki repository
|
||||
JGitUtil.cloneRepository(
|
||||
getWikiRepositoryDir(repository.owner, repository.name),
|
||||
getWikiRepositoryDir(accountName, repository.name))
|
||||
JGitUtil.cloneRepository(getWikiRepositoryDir(repository.owner, repository.name),
|
||||
FileUtil.deleteIfExists(getWikiRepositoryDir(accountName, repository.name)))
|
||||
|
||||
// Copy files
|
||||
FileUtils.copyDirectory(
|
||||
Directory.getRepositoryFilesDir(repository.owner, repository.name),
|
||||
Directory.getRepositoryFilesDir(accountName, repository.name)
|
||||
)
|
||||
val repositoryFilesDir = getRepositoryFilesDir(repository.owner, repository.name)
|
||||
if(repositoryFilesDir.exists){
|
||||
FileUtils.copyDirectory(
|
||||
repositoryFilesDir,
|
||||
FileUtil.deleteIfExists(getRepositoryFilesDir(accountName, repository.name)))
|
||||
}
|
||||
|
||||
// Record activity
|
||||
recordForkActivity(repository.owner, repository.name, loginUserName, accountName)
|
||||
|
||||
@@ -68,9 +68,24 @@ object FileUtil {
|
||||
|
||||
def readableSize(size: Long): String = FileUtils.byteCountToDisplaySize(size)
|
||||
|
||||
/**
|
||||
* Delete the given directory if it's empty.
|
||||
* Do nothing if the given File is not a directory or not empty.
|
||||
*/
|
||||
def deleteDirectoryIfEmpty(dir: File): Unit = {
|
||||
if(dir.isDirectory() && dir.list().isEmpty) {
|
||||
FileUtils.deleteDirectory(dir)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete file or directory forcibly.
|
||||
*/
|
||||
def deleteIfExists(file: java.io.File): java.io.File = {
|
||||
if(file.exists){
|
||||
FileUtils.forceDelete(file)
|
||||
}
|
||||
file
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user