Goit

Simple and lightweight Git web server
git clone http://git.omkov.net/Goit
Log | Tree | Refs | README | Download

AuthorJakob Wakeling <[email protected]>
Date2023-12-23 22:00:09
Commit70fd6ec3e76cb05bd54c9f923ed115f95cfc3cdc
Parent19cde21a51907cc6984688be11fc2475d665df88

Ensure directories exist when moving a repository

Diffstat

M src/goit/repo.go | 6 ++++++

1 files changed, 6 insertions, 0 deletions

diff --git a/src/goit/repo.go b/src/goit/repo.go
index 7c22f94..f0d86da 100644
--- a/src/goit/repo.go
+++ b/src/goit/repo.go
@@ -8,6 +8,7 @@ import (
 	"errors"
 	"log"
 	"os"
+	"path/filepath"
 	"strings"
 
 	"github.com/Jamozed/Goit/src/util"
@@ -183,6 +184,11 @@ func UpdateRepo(rid int64, repo Repo) error {
 	}
 
 	if repo.Name != old.Name {
+		if err := os.MkdirAll(filepath.Dir(RepoPath(repo.Name, true)), 0o777); err != nil {
+			tx.Rollback()
+			return err
+		}
+
 		if err := os.Rename(RepoPath(old.Name, true), RepoPath(repo.Name, true)); err != nil {
 			tx.Rollback()
 			return err