From 65f2ec198e4d7a1802c243eb157201685963fe94 Mon Sep 17 00:00:00 2001 From: SwayKh Date: Fri, 4 Oct 2024 22:37:22 +0530 Subject: [PATCH] Move the Linking Log message to all Link()/Unlink() calls. Probably bad, but allow for printing Aliased paths to Logs --- commands/add.go | 10 ++++++++++ commands/linksym.go | 3 --- commands/remove.go | 7 ++++++- link/link.go | 1 - 4 files changed, 16 insertions(+), 5 deletions(-) diff --git a/commands/add.go b/commands/add.go index cac0bb4..e8a7ff8 100644 --- a/commands/add.go +++ b/commands/add.go @@ -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 @@ -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) diff --git a/commands/linksym.go b/commands/linksym.go index 14a63de..e38c3fd 100644 --- a/commands/linksym.go +++ b/commands/linksym.go @@ -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 ") - } err = app.Remove(args) case "source": if len(args) > 0 { diff --git a/commands/remove.go b/commands/remove.go index a39811b..e2da058 100644 --- a/commands/remove.go +++ b/commands/remove.go @@ -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 diff --git a/link/link.go b/link/link.go index 8cb93fa..d5a29bc 100644 --- a/link/link.go +++ b/link/link.go @@ -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)