mirror of
https://github.com/yarlson/lnk.git
synced 2025-08-30 17:59:47 +02:00
fix: handle return values in error cleanup blocks (golangci-lint)
This commit is contained in:
@@ -89,15 +89,15 @@ func (l *Lnk) Add(filePath string) error {
|
||||
// Create symlink
|
||||
if err := l.fs.CreateSymlink(destPath, absPath); err != nil {
|
||||
// Try to restore the file if symlink creation fails
|
||||
l.fs.MoveFile(destPath, absPath)
|
||||
_ = l.fs.MoveFile(destPath, absPath) // Ignore error in cleanup
|
||||
return fmt.Errorf("failed to create symlink: %w", err)
|
||||
}
|
||||
|
||||
// Stage and commit the file
|
||||
if err := l.git.AddAndCommit(basename, fmt.Sprintf("lnk: added %s", basename)); err != nil {
|
||||
// Try to restore the original state if commit fails
|
||||
os.Remove(absPath)
|
||||
l.fs.MoveFile(destPath, absPath)
|
||||
_ = os.Remove(absPath) // Ignore error in cleanup
|
||||
_ = l.fs.MoveFile(destPath, absPath) // Ignore error in cleanup
|
||||
return fmt.Errorf("failed to commit changes: %w", err)
|
||||
}
|
||||
|
||||
@@ -143,8 +143,8 @@ func (l *Lnk) Remove(filePath string) error {
|
||||
// Remove from Git and commit
|
||||
if err := l.git.RemoveAndCommit(basename, fmt.Sprintf("lnk: removed %s", basename)); err != nil {
|
||||
// Try to restore the symlink if commit fails
|
||||
l.fs.MoveFile(absPath, target)
|
||||
l.fs.CreateSymlink(target, absPath)
|
||||
_ = l.fs.MoveFile(absPath, target) // Ignore error in cleanup
|
||||
_ = l.fs.CreateSymlink(target, absPath) // Ignore error in cleanup
|
||||
return fmt.Errorf("failed to commit changes: %w", err)
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user