Skip to content

Commit

Permalink
Fix directory renaming on username change (thomiceli#205)
Browse files Browse the repository at this point in the history
* src/dest dirs have to be lowercase
* if the src dir doesn't exist, don't rename
  • Loading branch information
thomiceli committed Jan 6, 2024
1 parent 46482a9 commit 749529a
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions internal/web/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"crypto/md5"
"fmt"
"github.com/thomiceli/opengist/internal/config"
"github.com/thomiceli/opengist/internal/git"
"os"
"path/filepath"
"strconv"
Expand Down Expand Up @@ -162,11 +163,14 @@ func usernameProcess(ctx echo.Context) error {
return redirect(ctx, "/settings")
}

err := os.Rename(
filepath.Join(config.C.OpengistHome, "repos", user.Username),
filepath.Join(config.C.OpengistHome, "repos", dto.Username))
if err != nil {
return errorRes(500, "Cannot rename user directory", err)
sourceDir := filepath.Join(config.C.OpengistHome, git.ReposDirectory, strings.ToLower(user.Username))
destinationDir := filepath.Join(config.C.OpengistHome, git.ReposDirectory, strings.ToLower(dto.Username))

if _, err := os.Stat(sourceDir); !os.IsNotExist(err) {
err := os.Rename(sourceDir, destinationDir)
if err != nil {
return errorRes(500, "Cannot rename user directory", err)
}
}

user.Username = dto.Username
Expand Down

0 comments on commit 749529a

Please sign in to comment.