diff options
Diffstat (limited to 'rhimport')
-rw-r--r-- | rhimport/core.go | 5 | ||||
-rw-r--r-- | rhimport/fetcher.go | 33 |
2 files changed, 24 insertions, 14 deletions
diff --git a/rhimport/core.go b/rhimport/core.go index 413e39c..29f03ba 100644 --- a/rhimport/core.go +++ b/rhimport/core.go @@ -39,6 +39,11 @@ const ( CUT_MAX = 999 // not sure if rdxport.cgi can handle filesizes > MAX(INT32) FILESIZE_MAX = (2 * 1024 * 1024 * 1024) - 1 + + // TODO: make this configurable + ARCHIV_HOST = "archiv.helsinki.at" + ARCHIV_USER = "rhimport" + ARCHIV_BASE_PATH = "/srv/archiv" ) var ( diff --git a/rhimport/fetcher.go b/rhimport/fetcher.go index 1abf736..e398361 100644 --- a/rhimport/fetcher.go +++ b/rhimport/fetcher.go @@ -221,8 +221,7 @@ func generateArchivFilePath(uri *url.URL) (file, path string, err error) { } file = t.Format("2006-01-02-1504") + ".ogg" - // TODO: make basepath configurable - path = fmt.Sprintf("/srv/archiv/%04d/%02d-%s/%02d-%s", t.Year(), t.Month(), months[t.Month()-1], t.Day(), weekdays[t.Weekday()]) + path = fmt.Sprintf("%s/%04d/%02d-%s/%02d-%s", ARCHIV_BASE_PATH, t.Year(), t.Month(), months[t.Month()-1], t.Day(), weekdays[t.Weekday()]) return } @@ -244,10 +243,9 @@ func fetchFileArchiv(ctx *Context, res *Result, uri *url.URL) (err error) { } defer easy.Cleanup() - // TODO: make user and host configurable - scpuri := fmt.Sprintf("sftp://archiv.helsinki.at%s/%s", srcpath, srcfile) + scpuri := fmt.Sprintf("sftp://%s%s/%s", ARCHIV_HOST, srcpath, srcfile) easy.Setopt(curl.OPT_URL, scpuri) - easy.Setopt(curl.OPT_USERNAME, "rhimport") + easy.Setopt(curl.OPT_USERNAME, ARCHIV_USER) u, _ := user.Current() easy.Setopt(curl.OPT_SSH_PUBLIC_KEYFILE, fmt.Sprintf("%s/.ssh/id_rsa.pub", u.HomeDir)) @@ -317,9 +315,16 @@ func fetchFileTmp(ctx *Context, res *Result, uri *url.URL) (err error) { } func fetchFileDirConvert(ctx *Context, res *Result, origSrc *os.File, sizeTotal int64) (err error) { + + basepath, err := ioutil.TempDir(ctx.conf.TempDir, "rhimportd-") + if err != nil { + return err + } + origDir, origFile := path.Split(ctx.SourceFile) + var conv FetchConverter - if conv, ctx.SourceFile, err = NewFetchConverter(ctx.FetchConverter, ctx.SourceFile); err != nil { - rhl.Printf("Unable to create converter for file %s: %s", origSrc.Name(), err) + if conv, ctx.SourceFile, err = NewFetchConverter(ctx.FetchConverter, filepath.Join(basepath, origFile)); err != nil { + rhl.Printf("Unable to create converter for file %s: %s", origDir+origFile, err) return } @@ -334,7 +339,7 @@ func fetchFileDirConvert(ctx *Context, res *Result, origSrc *os.File, sizeTotal break } if err != nil { - rhl.Printf("Unable to read from source file %s: %s", origSrc.Name(), err) + rhl.Printf("Unable to read from source file %s: %s", origDir+origFile, err) break } w, err = conv.Write(buffer[0:r]) @@ -363,7 +368,6 @@ func fetchFileDirConvert(ctx *Context, res *Result, origSrc *os.File, sizeTotal return err } - // TODO: delete origSrc file when SourceFilePolicy == delete or DeleteWithDir switch ctx.SourceFilePolicy { case Auto: ctx.DeleteSourceFile = true @@ -371,11 +375,15 @@ func fetchFileDirConvert(ctx *Context, res *Result, origSrc *os.File, sizeTotal case Keep: ctx.DeleteSourceFile = false ctx.DeleteSourceDir = false + case Delete: + ctx.DeleteSourceDir = true + ctx.DeleteSourceFile = true + os.Remove(origDir + origFile) case DeleteWithDir: ctx.DeleteSourceDir = true - fallthrough - case Delete: ctx.DeleteSourceFile = true + os.Remove(origDir + origFile) + os.Remove(origDir) } return @@ -585,9 +593,6 @@ func fetchFileAttachment(ctx *Context, res *Result, uri *url.URL) error { type FetchFunc func(*Context, *Result, *url.URL) (err error) -// TODO: implement fetchers for: -// public:// -// home:// ????? var ( fetchers = map[string]FetchFunc{ "local": fetchFileLocal, |