Skip to content

Commit

Permalink
skip downloading when file protocol is file:// (#201)
Browse files Browse the repository at this point in the history
* skip downloading local files

* updated csv and json clients to separate reading remote and local files

Co-authored-by: Maziar <maziar@appbase.io>
  • Loading branch information
siddharthlatest and Maziar committed Oct 15, 2021
1 parent 1d98385 commit 599f67d
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 21 deletions.
17 changes: 10 additions & 7 deletions importer/adaptor/csv/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,14 +114,17 @@ func (c *Client) initConnection() error {
var name string
name = strings.Replace(c.uri, "file://", "", 1)

// read file from remote url
if url, err := url.ParseRequestURI(c.uri); err == nil {
name = fmt.Sprintf("%s/%s.csv", common.DefaultDownloadDirectory, fmt.Sprintf("%d", time.Now().Unix()))
if err := common.DownloadFile(name, url.String()); err != nil {
return err
// read file from remote url if protocol contains http
proto := strings.Split(c.uri, "//")
if strings.Contains(proto[0], `http`) {
if url, err := url.ParseRequestURI(c.uri); err == nil {
name = fmt.Sprintf("%s/%s.csv", common.DefaultDownloadDirectory, fmt.Sprintf("%d", time.Now().Unix()))
if err := common.DownloadFile(name, url.String()); err != nil {
return err
}
log.Infoln("Download complete for:", name)
c.deleteFileAfterUsage = true
}
log.Infoln("Download complete for:", name)
c.deleteFileAfterUsage = true
}
f, err := os.OpenFile(name, os.O_RDWR, 0666)
if err != nil {
Expand Down
19 changes: 11 additions & 8 deletions importer/adaptor/json/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,15 +99,18 @@ func (c *Client) initFile() error {
var name string
name = strings.Replace(c.uri, "file://", "", 1)

// read file from remote url
if url, err := url.ParseRequestURI(c.uri); err == nil {
name = fmt.Sprintf("%s/%s.csv", common.DefaultDownloadDirectory, fmt.Sprintf("%d", time.Now().Unix()))
if err := common.DownloadFile(name, url.String()); err != nil {
return err
// read file from remote url if protocol contains http
proto := strings.Split(c.uri, "//")
if strings.Contains(proto[0], `http`) {
if url, err := url.ParseRequestURI(c.uri); err == nil {
name = fmt.Sprintf("%s/%s.csv", common.DefaultDownloadDirectory, fmt.Sprintf("%d", time.Now().Unix()))
if err := common.DownloadFile(name, url.String()); err != nil {
return err
}
log.Infoln("Download complete for:", name)
c.uri = name
c.deleteFileAfterUsage = true
}
log.Infoln("Download complete for:", name)
c.uri = name
c.deleteFileAfterUsage = true
}

f, err := os.OpenFile(name, os.O_RDWR, 0666)
Expand Down
15 changes: 9 additions & 6 deletions importer/adaptor/jsonl/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,16 @@ func (c *Client) initFile() error {
return nil
}
name := strings.Replace(c.uri, "file://", "", 1)
if url, err := url.ParseRequestURI(c.uri); err == nil {
name = fmt.Sprintf("%s/%s.csv", common.DefaultDownloadDirectory, fmt.Sprintf("%d", time.Now().Unix()))
if err := common.DownloadFile(name, url.String()); err != nil {
return err
proto := strings.Split(c.uri, "//")
if strings.Contains(proto[0], `http`) {
if url, err := url.ParseRequestURI(c.uri); err == nil {
name = fmt.Sprintf("%s/%s.csv", common.DefaultDownloadDirectory, fmt.Sprintf("%d", time.Now().Unix()))
if err := common.DownloadFile(name, url.String()); err != nil {
return err
}
log.Infoln("Download complete for:", name)
c.deleteFileAfterUsage = true
}
log.Infoln("Download complete for:", name)
c.deleteFileAfterUsage = true
}

f, err := os.OpenFile(name, os.O_RDWR, 0666)
Expand Down

0 comments on commit 599f67d

Please sign in to comment.