Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix directory rename bugs on username change: #205

Merged
merged 1 commit into from
Jan 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Fix directory rename bugs on username change:
* src/dest dirs have to be lowercase
* if the src dir doesn't exist, don't rename
  • Loading branch information
thomiceli committed Jan 5, 2024
commit 8e2cc04406fbe28e4ccff561cc135a409a91fe8b
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