mirror of
https://github.com/thomiceli/opengist.git
synced 2024-12-22 20:42:40 +00:00
Fix directory renaming on username change (#205)
* src/dest dirs have to be lowercase * if the src dir doesn't exist, don't rename
This commit is contained in:
parent
10cf7e6e25
commit
a1524af7a9
1 changed files with 9 additions and 5 deletions
|
@ -4,6 +4,7 @@ import (
|
||||||
"crypto/md5"
|
"crypto/md5"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/thomiceli/opengist/internal/config"
|
"github.com/thomiceli/opengist/internal/config"
|
||||||
|
"github.com/thomiceli/opengist/internal/git"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
@ -162,11 +163,14 @@ func usernameProcess(ctx echo.Context) error {
|
||||||
return redirect(ctx, "/settings")
|
return redirect(ctx, "/settings")
|
||||||
}
|
}
|
||||||
|
|
||||||
err := os.Rename(
|
sourceDir := filepath.Join(config.C.OpengistHome, git.ReposDirectory, strings.ToLower(user.Username))
|
||||||
filepath.Join(config.C.OpengistHome, "repos", user.Username),
|
destinationDir := filepath.Join(config.C.OpengistHome, git.ReposDirectory, strings.ToLower(dto.Username))
|
||||||
filepath.Join(config.C.OpengistHome, "repos", dto.Username))
|
|
||||||
if err != nil {
|
if _, err := os.Stat(sourceDir); !os.IsNotExist(err) {
|
||||||
return errorRes(500, "Cannot rename user directory", err)
|
err := os.Rename(sourceDir, destinationDir)
|
||||||
|
if err != nil {
|
||||||
|
return errorRes(500, "Cannot rename user directory", err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
user.Username = dto.Username
|
user.Username = dto.Username
|
||||||
|
|
Loading…
Reference in a new issue