diff options
author | Christian Pointner <equinox@helsinki.at> | 2015-12-30 22:44:30 (GMT) |
---|---|---|
committer | Christian Pointner <equinox@helsinki.at> | 2015-12-30 22:44:30 (GMT) |
commit | 399f26ca052c09ed54f812343a33d82560d9ae48 (patch) | |
tree | fdd975cc5adf9d78cb0ff13ddea31399b30785ca | |
parent | d4ef4d60994605e2a8251844c7eec166ee4094ec (diff) |
improved sanity check for local files
-rw-r--r-- | fetcher.go | 18 |
1 files changed, 17 insertions, 1 deletions
@@ -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 |