Fix up the filesystem summary logger
This commit is contained in:
@@ -15,6 +15,7 @@ type FileSystem interface {
|
||||
MkdirAll(path string, perm os.FileMode) error
|
||||
Symlink(source, target string) error
|
||||
Link(source, target string) error
|
||||
RecordLinkAttempt(kind string, source, target string, err error, dryRun bool)
|
||||
SummaryLines() []string
|
||||
IsDryRun() bool
|
||||
}
|
||||
@@ -52,7 +53,10 @@ func (r operationRecord) summaryLine() (string, bool) {
|
||||
status = "DRY-RUN"
|
||||
}
|
||||
|
||||
return fmt.Sprintf("%s %s -> %s (%s)", kindLabel, r.source, r.target, status), true
|
||||
source := FormatSourcePath(r.source)
|
||||
target := FormatTargetPath(r.target)
|
||||
|
||||
return fmt.Sprintf("%s %s → %s (%s)", kindLabel, source, target, status), true
|
||||
}
|
||||
|
||||
type baseFileSystem struct {
|
||||
@@ -119,16 +123,20 @@ func (fs *realFileSystem) MkdirAll(path string, perm os.FileMode) error {
|
||||
|
||||
func (fs *realFileSystem) Symlink(source, target string) error {
|
||||
err := os.Symlink(source, target)
|
||||
fs.addOperation(opSymlink, source, target, err, false)
|
||||
fs.RecordLinkAttempt(opSymlink, source, target, err, false)
|
||||
return err
|
||||
}
|
||||
|
||||
func (fs *realFileSystem) Link(source, target string) error {
|
||||
err := os.Link(source, target)
|
||||
fs.addOperation(opHardlink, source, target, err, false)
|
||||
fs.RecordLinkAttempt(opHardlink, source, target, err, false)
|
||||
return err
|
||||
}
|
||||
|
||||
func (fs *realFileSystem) RecordLinkAttempt(kind string, source, target string, err error, dryRun bool) {
|
||||
fs.addOperation(kind, source, target, err, dryRun)
|
||||
}
|
||||
|
||||
func (fs *realFileSystem) SummaryLines() []string {
|
||||
return summarizeOperations(fs.snapshot())
|
||||
}
|
||||
@@ -162,15 +170,19 @@ func (fs *dryRunFileSystem) MkdirAll(path string, perm os.FileMode) error {
|
||||
}
|
||||
|
||||
func (fs *dryRunFileSystem) Symlink(source, target string) error {
|
||||
fs.addOperation(opSymlink, source, target, nil, true)
|
||||
fs.RecordLinkAttempt(opSymlink, source, target, nil, true)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (fs *dryRunFileSystem) Link(source, target string) error {
|
||||
fs.addOperation(opHardlink, source, target, nil, true)
|
||||
fs.RecordLinkAttempt(opHardlink, source, target, nil, true)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (fs *dryRunFileSystem) RecordLinkAttempt(kind string, source, target string, err error, dryRun bool) {
|
||||
fs.addOperation(kind, source, target, err, dryRun)
|
||||
}
|
||||
|
||||
func (fs *dryRunFileSystem) SummaryLines() []string {
|
||||
return summarizeOperations(fs.snapshot())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user