summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Pointner <equinox@helsinki.at>2015-12-30 22:44:30 (GMT)
committerChristian Pointner <equinox@helsinki.at>2015-12-30 22:44:30 (GMT)
commit620d1b76807f6ecffda54347db7b58107d03c2a5 (patch)
treeee6ffc49c9d63301a7961fe1f0a6bc8952ad7077 /src
parent1a817c9f42dfbc4f3f80281e748a8a008b771533 (diff)
improved sanity check for local files
Diffstat (limited to 'src')
-rw-r--r--src/helsinki.at/rhimport/fetcher.go18
1 files changed, 17 insertions, 1 deletions
diff --git a/src/helsinki.at/rhimport/fetcher.go b/src/helsinki.at/rhimport/fetcher.go
index 81072eb..f1bbb5e 100644
--- a/src/helsinki.at/rhimport/fetcher.go
+++ b/src/helsinki.at/rhimport/fetcher.go
@@ -158,7 +158,7 @@ func FetchFileCurl(ctx *ImportContext, res *FetchResult, uri *url.URL) (err erro
func FetchFileLocal(ctx *ImportContext, res *FetchResult, uri *url.URL) (err error) {
rhl.Printf("Local fetcher called for '%s'", ctx.SourceUri)
if ctx.ProgressCallBack != nil {
- if keep := ctx.ProgressCallBack(1, "fetching", 1.0, ctx.ProgressCallBackData); !keep {
+ if keep := ctx.ProgressCallBack(1, "fetching", 0.0, ctx.ProgressCallBackData); !keep {
ctx.ProgressCallBack = nil
}
}
@@ -170,7 +170,23 @@ func FetchFileLocal(ctx *ImportContext, res *FetchResult, uri *url.URL) (err err
res.ErrorString = fmt.Sprintf("local-file open(): %s", err)
return nil
}
+ if info, err := src.Stat(); err != nil {
+ res.ResponseCode = http.StatusBadRequest
+ res.ErrorString = fmt.Sprintf("local-file stat(): %s", err)
+ return nil
+ } else {
+ if info.IsDir() {
+ res.ResponseCode = http.StatusBadRequest
+ res.ErrorString = fmt.Sprintf("'%s' is a directory", ctx.SourceFile)
+ return nil
+ }
+ }
src.Close()
+ if ctx.ProgressCallBack != nil {
+ if keep := ctx.ProgressCallBack(1, "fetching", 1.0, ctx.ProgressCallBackData); !keep {
+ ctx.ProgressCallBack = nil
+ }
+ }
ctx.DeleteSourceFile = false
ctx.DeleteSourceDir = false
return