From 620d1b76807f6ecffda54347db7b58107d03c2a5 Mon Sep 17 00:00:00 2001
From: Christian Pointner
Date: Wed, 30 Dec 2015 23:44:30 +0100
Subject: improved sanity check for local files
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
diff --git a/test/socket.html b/test/socket.html
index 4d26667..c179456 100644
--- a/test/socket.html
+++ b/test/socket.html
@@ -58,9 +58,7 @@
switch (msg.TYPE) {
case "ack":
$('#sessionid').val(msg.ID);
- $('#buttonrun').attr('disabled','disabled')
- $('#buttonreconnect').attr('disabled','disabled')
- $('#buttoncancel').removeAttr('disabled')
+ buttonsRunning();
break;
case "done":
case "error":
@@ -86,12 +84,12 @@
function run() {
req = { COMMAND: "new",
TIMEOUT: 200,
- REFERENCE_ID: "my-very-personal-import",
+ REFERENCE_ID: $('#refid').val(),
LOGIN_NAME: $('#username').val(),
PASSWORD: $('#token').val(),
SHOW_ID: 10002,
CLEAR_SHOW_CARTS: true,
- SOURCE_URI: "fake://10000" };
+ SOURCE_URI: $('#source').val() };
s = new Session(req);
}
@@ -106,12 +104,29 @@
s.cancel();
}
- function init() {
- $('#sessionid').val("");
+ function detach() {
+ s.sock.close();
+ buttonsIdle();
+ }
+
+ function buttonsIdle() {
$('#buttonrun').removeAttr('disabled')
$('#buttonreconnect').removeAttr('disabled')
+ $('#buttondetach').attr('disabled','disabled')
$('#buttoncancel').attr('disabled','disabled')
}
+
+ function buttonsRunning() {
+ $('#buttonrun').attr('disabled','disabled')
+ $('#buttonreconnect').attr('disabled','disabled')
+ $('#buttondetach').removeAttr('disabled')
+ $('#buttoncancel').removeAttr('disabled')
+ }
+
+ function init() {
+ $('#sessionid').val("");
+ buttonsIdle();
+ }
@@ -131,7 +146,10 @@
+
+
+
--
cgit v0.10.2