Moves default clean file checks to the helper package
This commit is contained in:
parent
345b99cc0c
commit
b2f45d6add
@ -32,26 +32,12 @@ func Clean(path string, opts *settings.Settings) {
|
|||||||
// Remove score files
|
// Remove score files
|
||||||
for i := range scores {
|
for i := range scores {
|
||||||
scores[i].GenerateOutputPath(opts)
|
scores[i].GenerateOutputPath(opts)
|
||||||
if helpers.Exists(scores[i].OutputPath) {
|
helpers.CleanFile(scores[i].OutputPath)
|
||||||
if err := os.Remove(scores[i].OutputPath); err != nil {
|
|
||||||
log.WithFields(log.Fields{
|
|
||||||
"error": err,
|
|
||||||
"score": scores[i],
|
|
||||||
}).Error("unable to delete file")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove LaTeX resources
|
// Remove LaTeX resources
|
||||||
texPath := filepath.Join(opts.OutputDir, opts.Name+".tex")
|
texPath := filepath.Join(opts.OutputDir, opts.Name+".tex")
|
||||||
if helpers.Exists(texPath) {
|
helpers.CleanFile(texPath)
|
||||||
if err := os.Remove(texPath); err != nil {
|
|
||||||
log.WithFields(log.Fields{
|
|
||||||
"error": err,
|
|
||||||
"file": texPath,
|
|
||||||
}).Error("unable to delete file")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for i := range opts.LatexResources {
|
for i := range opts.LatexResources {
|
||||||
path := filepath.Join(opts.OutputDir, filepath.Base(opts.LatexResources[i]))
|
path := filepath.Join(opts.OutputDir, filepath.Base(opts.LatexResources[i]))
|
||||||
err := os.RemoveAll(path)
|
err := os.RemoveAll(path)
|
||||||
@ -65,12 +51,5 @@ func Clean(path string, opts *settings.Settings) {
|
|||||||
|
|
||||||
// Remove target songbook
|
// Remove target songbook
|
||||||
songbookPath := filepath.Join(opts.OutputDir, opts.Name+".pdf")
|
songbookPath := filepath.Join(opts.OutputDir, opts.Name+".pdf")
|
||||||
if helpers.Exists(songbookPath) {
|
helpers.CleanFile(songbookPath)
|
||||||
if err := os.Remove(songbookPath); err != nil {
|
|
||||||
log.WithFields(log.Fields{
|
|
||||||
"error": err,
|
|
||||||
"songbook": songbookPath,
|
|
||||||
}).Error("unable to delete file")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -99,3 +99,16 @@ func AbsolutePath(path, root string) string {
|
|||||||
}
|
}
|
||||||
return filepath.Join(root, path)
|
return filepath.Join(root, path)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CleanFile removes the file on the given path if it exists. In case of
|
||||||
|
// failure, an error will be logged.
|
||||||
|
func CleanFile(path string) {
|
||||||
|
if Exists(path) {
|
||||||
|
if err := os.Remove(path); err != nil {
|
||||||
|
log.WithFields(log.Fields{
|
||||||
|
"error": err,
|
||||||
|
"file": path,
|
||||||
|
}).Error("unable to delete file")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user