Skip to content

Commit 78eff64

Browse files
committed
Make abspath Split return an abspath
1 parent 4564d4c commit 78eff64

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

abspath.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ func (abs absPath) Join(elems ...string) absPath {
6060
// Split breaks abs into stem and leaf parts (often directory and file, but not
6161
// necessarily), similar to filepath.Split. Unlike filepath.Split, the
6262
// resulting stem part does not have any trailing path separators.
63-
func (abs absPath) Split() (string, string) {
63+
func (abs absPath) Split() (absPath, string) {
6464
if abs == "" {
6565
return "", ""
6666
}
@@ -74,13 +74,13 @@ func (abs absPath) Split() (string, string) {
7474
dir = string(os.PathSeparator)
7575
}
7676

77-
return dir, base
77+
return absPath(dir), base
7878
}
7979

8080
// Dir returns the stem part of abs without the leaf, like filepath.Dir.
8181
func (abs absPath) Dir() string {
8282
dir, _ := abs.Split()
83-
return dir
83+
return string(dir)
8484
}
8585

8686
// Base returns the leaf part of abs without the stem, like filepath.Base.

main.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ func main() {
347347
}
348348
log := func() *logging.Logger {
349349
dir, file := makeAbsPath(*flErrorFile, absRoot).Split()
350-
return logging.New(dir, file, *flVerbose)
350+
return logging.New(dir.String(), file, *flVerbose)
351351
}()
352352
cmdRunner := cmd.NewRunner(log)
353353

@@ -1273,25 +1273,25 @@ func (git *repoSync) publishSymlink(ctx context.Context, worktree worktree) erro
12731273
linkDir, linkFile := git.link.Split()
12741274

12751275
// Make sure the link directory exists.
1276-
if err := os.MkdirAll(linkDir, defaultDirMode); err != nil {
1276+
if err := os.MkdirAll(linkDir.String(), defaultDirMode); err != nil {
12771277
return fmt.Errorf("error making symlink dir: %w", err)
12781278
}
12791279

12801280
// linkDir is absolute, so we need to change it to a relative path. This is
12811281
// so it can be volume-mounted at another path and the symlink still works.
1282-
targetRelative, err := filepath.Rel(linkDir, targetPath.String())
1282+
targetRelative, err := filepath.Rel(linkDir.String(), targetPath.String())
12831283
if err != nil {
12841284
return fmt.Errorf("error converting to relative path: %w", err)
12851285
}
12861286

12871287
const tmplink = "tmp-link"
12881288
git.log.V(2).Info("creating tmp symlink", "dir", linkDir, "link", tmplink, "target", targetRelative)
1289-
if err := os.Symlink(targetRelative, filepath.Join(linkDir, tmplink)); err != nil {
1289+
if err := os.Symlink(targetRelative, filepath.Join(linkDir.String(), tmplink)); err != nil {
12901290
return fmt.Errorf("error creating symlink: %w", err)
12911291
}
12921292

12931293
git.log.V(2).Info("renaming symlink", "root", linkDir, "oldName", tmplink, "newName", linkFile)
1294-
if err := os.Rename(filepath.Join(linkDir, tmplink), git.link.String()); err != nil {
1294+
if err := os.Rename(filepath.Join(linkDir.String(), tmplink), git.link.String()); err != nil {
12951295
return fmt.Errorf("error replacing symlink: %w", err)
12961296
}
12971297

@@ -1574,7 +1574,7 @@ func (git *repoSync) currentWorktree() (worktree, error) {
15741574
return worktree(target), nil
15751575
}
15761576
linkDir, _ := git.link.Split()
1577-
return worktree(absPath(linkDir).Join(target)), nil
1577+
return worktree(linkDir.Join(target)), nil
15781578
}
15791579

15801580
// SyncRepo syncs the repository to the desired ref, publishes it via the link,

0 commit comments

Comments
 (0)