-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
13115a7
commit ff769f6
Showing
1 changed file
with
41 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package reporters | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"path/filepath" | ||
) | ||
|
||
type reporterThatAutomaticallyApproves struct{} | ||
|
||
// NewQuietReporter creates a new reporter that does nothing. | ||
func NewReporterThatAutomaticallyApproves() Reporter { | ||
return &reporterThatAutomaticallyApproves{} | ||
} | ||
|
||
func (s *reporterThatAutomaticallyApproves) Report(approved, received string) bool { | ||
|
||
approvedFull, _ := filepath.Abs(approved) | ||
receivedFull, _ := filepath.Abs(received) | ||
|
||
// move the pending file to the approved location | ||
fmt.Printf("Automatically approving the received file\napproved: %v\nreceived: %v\n", approvedFull, receivedFull) | ||
|
||
// If the approved file exists, delete it, then rename it | ||
if _, err := os.Stat(approved); err == nil { | ||
err = os.Remove(approved) | ||
if err != nil { | ||
fmt.Printf("Error removing file: %v\n", err) | ||
return false | ||
} | ||
} | ||
|
||
err := os.Rename(received, approved) | ||
|
||
if err != nil { | ||
fmt.Printf("Error moving file: %v\n", err) | ||
return false | ||
} | ||
|
||
return true | ||
} |