diff options
Diffstat (limited to 'src/helsinki.at/rhimport/importer.go')
-rw-r--r-- | src/helsinki.at/rhimport/importer.go | 27 |
1 files changed, 26 insertions, 1 deletions
diff --git a/src/helsinki.at/rhimport/importer.go b/src/helsinki.at/rhimport/importer.go index 0f8eea8..0d0a836 100644 --- a/src/helsinki.at/rhimport/importer.go +++ b/src/helsinki.at/rhimport/importer.go @@ -55,6 +55,7 @@ type ImportContext struct { SourceUri string SourceFile string DeleteSourceFile bool + DeleteSourceDir bool } func NewImportContext(conf *Config, rddb *RdDb, user string, group string) *ImportContext { @@ -74,6 +75,7 @@ func NewImportContext(conf *Config, rddb *RdDb, user string, group string) *Impo ctx.UseMetaData = false ctx.SourceFile = "" ctx.DeleteSourceFile = false + ctx.DeleteSourceDir = false return ctx } @@ -173,8 +175,27 @@ func import_audio(ctx *ImportContext) (err error) { return } +func cleanup_files(ctx *ImportContext) { + if(ctx.DeleteSourceFile) { + rhdl.Printf("importer: removing file: %s", ctx.SourceFile) + if err := os.Remove(ctx.SourceFile); err != nil { + rhl.Printf("importer: error removing source file: %s", err) + return + } + if(ctx.DeleteSourceDir) { + dir := path.Dir(ctx.SourceFile) + rhdl.Printf("importer: also removing directory: %s", dir) + if err := os.Remove(dir); err != nil { + rhl.Printf("importer: error removing source directory: %s", err) + } + } + } + return +} + func ImportFile(ctx *ImportContext) (err error) { rhl.Println("ImportFile called for", ctx.SourceFile) + defer cleanup_files(ctx) if ctx.Trusted { if err = ctx.getPassword(true); err != nil { @@ -182,5 +203,9 @@ func ImportFile(ctx *ImportContext) (err error) { } } - return import_audio(ctx) + if err = import_audio(ctx); err != nil { + return + } + + return } |