diff options
author | Christian Pointner <equinox@helsinki.at> | 2015-12-10 14:56:01 (GMT) |
---|---|---|
committer | Christian Pointner <equinox@helsinki.at> | 2015-12-10 14:56:01 (GMT) |
commit | ce68e63d07aa6efa926601298a472818ae6a37a6 (patch) | |
tree | d973d9ba72b0ff519c093e52eb7cca04514b1c24 /src/helsinki.at/rhimport/importer.go | |
parent | 7961a53e39adc0fb434ff212d17a689513eeaf5c (diff) |
importer deletes source file and dir if requested
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 } |