Skip to content

Commit

Permalink
Move the Linking Log message to all Link()/Unlink() calls. Probably b…
Browse files Browse the repository at this point in the history
…ad, but allow for printing Aliased paths to Logs
  • Loading branch information
SwayKh committed Oct 4, 2024
1 parent 1c7109b commit 65f2ec1
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 5 deletions.
10 changes: 10 additions & 0 deletions commands/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ func (app *Application) Add(args []string, updateRecord bool) error {

logger.VerboseLog(logger.SUCCESS, "Destination path exists: %s", config.AliasPath(destinationPath, app.HomeDirectory, app.InitDirectory, true))

aliasSourcePath := config.AliasPath(sourcePath, app.HomeDirectory, app.InitDirectory, true)
aliasDestinationPath := config.AliasPath(destinationPath, app.HomeDirectory, app.InitDirectory, true)

logger.Log(logger.INFO, "Moving: %s to %s", aliasSourcePath, aliasDestinationPath)

err = link.MoveAndLink(sourcePath, destinationPath, source.IsDir)
if err != nil {
return err
Expand Down Expand Up @@ -143,6 +148,11 @@ func (app *Application) Add(args []string, updateRecord bool) error {
}

if toMove {
aliasSourcePath := config.AliasPath(sourcePath, app.HomeDirectory, app.InitDirectory, true)
aliasDestinationPath := config.AliasPath(destinationPath, app.HomeDirectory, app.InitDirectory, true)

logger.Log(logger.INFO, "Moving: %s to %s", aliasSourcePath, aliasDestinationPath)

err = link.MoveAndLink(sourcePath, destinationPath, isSourceDir)
} else {
err = link.Link(sourcePath, destinationPath)
Expand Down
3 changes: 0 additions & 3 deletions commands/linksym.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,6 @@ func (app *Application) Run() error {
}
err = app.Add(args, true)
case "remove":
if len(args) > 1 {
return fmt.Errorf("'remove' subcommand doesn't accept more than 1 argument.\nUsage: linksym remove <file name>")
}
err = app.Remove(args)
case "source":
if len(args) > 0 {
Expand Down
7 changes: 6 additions & 1 deletion commands/remove.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,15 @@ func (app *Application) Remove(args []string) error {
}
}

aliasLinkPath := config.AliasPath(linkInfo.AbsPath, app.HomeDirectory, app.InitDirectory, true)
aliasSourcePath := config.AliasPath(sourcePath, app.HomeDirectory, app.InitDirectory, true)
aliasDestinationPath := config.AliasPath(destinationPath, app.HomeDirectory, app.InitDirectory, true)

if !found {
return fmt.Errorf("No record found for %s", config.AliasPath(linkInfo.AbsPath, app.HomeDirectory, app.InitDirectory, true))
return fmt.Errorf("No record found for %s", aliasLinkPath)
}

logger.Log(logger.INFO, "Moving: %s to %s", aliasSourcePath, aliasDestinationPath)
err = link.UnLink(sourcePath, destinationPath, linkInfo.IsDir)
if err != nil {
return err
Expand Down
1 change: 0 additions & 1 deletion link/link.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ func UnLink(sourcePath, destinationPath string, isDirectory bool) error {
// destination and then remove the source. This method allows better handling
// when linking across file system than just renaming files
func moveFile(source, destination string) error {
logger.Log(logger.INFO, "Moving: %s to %s", source, destination)
src, err := os.Open(source)
if err != nil {
return fmt.Errorf("Failed to open file: %s: %w", source, err)
Expand Down

0 comments on commit 65f2ec1

Please sign in to comment.