Skip to content

Commit

Permalink
Adds an error when the file/folder mentioned in a remote attribute is…
Browse files Browse the repository at this point in the history
… not found
  • Loading branch information
mik-dass committed May 5, 2021
1 parent edadc46 commit 1042ce6
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 3 deletions.
10 changes: 10 additions & 0 deletions pkg/util/file_indexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package util

import (
"encoding/json"
"fmt"
"io/ioutil"
"os"
"path/filepath"
Expand Down Expand Up @@ -385,6 +386,9 @@ func runIndexerWithExistingFileIndex(directory string, ignoreRules []string, rem
if err != nil {
return IndexerRet{}, err
}
if len(matches) == 0 {
return IndexerRet{}, fmt.Errorf("path %q doens't exist", remoteAttribute)
}
for _, fileName := range matches {
if checkFileExist(fileName) {
// Fetch path of source file relative to that of source base path so that it can be passed to recursiveTar
Expand Down Expand Up @@ -437,6 +441,8 @@ func runIndexerWithExistingFileIndex(directory string, ignoreRules []string, rem
for _, remote := range innerRet.FilesDeleted {
filesDeleted[remote] = true
}
} else {
return IndexerRet{}, fmt.Errorf("path %q doens't exist", fileName)
}
}
}
Expand Down Expand Up @@ -509,6 +515,10 @@ func recursiveChecker(directory, srcBase, srcFile, destBase, destFile string, ig
return IndexerRet{}, err
}

if len(matchedPathsDir) == 0 {
return IndexerRet{}, fmt.Errorf("path %q doens't exist", joinedPath)
}

joinedRelPath, err := filepath.Rel(directory, joinedPath)
if err != nil {
return IndexerRet{}, err
Expand Down
32 changes: 29 additions & 3 deletions pkg/util/file_indexer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -855,7 +855,7 @@ func Test_recursiveChecker(t *testing.T) {
want: IndexerRet{
NewFileMap: map[string]FileData{},
},
wantErr: false,
wantErr: true,
},
{
name: "case 19: folder doesn't exist",
Expand All @@ -871,7 +871,7 @@ func Test_recursiveChecker(t *testing.T) {
want: IndexerRet{
NewFileMap: map[string]FileData{},
},
wantErr: false,
wantErr: true,
},

{
Expand Down Expand Up @@ -1230,7 +1230,7 @@ func Test_runIndexerWithExistingFileIndex(t *testing.T) {
args: args{
directory: tempDirectoryName,
ignoreRules: []string{},
remoteDirectories: map[string]string{"blah": "new/Blah", htmlRelFilePath: "new/Folder0/view.html", viewsFolderStat.Name(): "new/Folder"},
remoteDirectories: map[string]string{htmlRelFilePath: "new/Folder0/view.html", viewsFolderStat.Name(): "new/Folder"},
existingFileIndex: &FileIndex{
Files: map[string]FileData{
htmlRelFilePath: {
Expand Down Expand Up @@ -1463,6 +1463,32 @@ func Test_runIndexerWithExistingFileIndex(t *testing.T) {
},
wantErr: false,
},
{
name: "case 15: local file doesn't exist",
args: args{
directory: tempDirectoryName,
ignoreRules: []string{},
remoteDirectories: map[string]string{htmlRelFilePath + "blah": htmlRelFilePath},
existingFileIndex: &FileIndex{
Files: map[string]FileData{},
},
},
wantRet: IndexerRet{},
wantErr: true,
},
{
name: "case 16: local folder doesn't exist",
args: args{
directory: tempDirectoryName,
ignoreRules: []string{},
remoteDirectories: map[string]string{viewsFolderPath + "blah": viewsFolderPath},
existingFileIndex: &FileIndex{
Files: map[string]FileData{},
},
},
wantRet: IndexerRet{},
wantErr: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down

0 comments on commit 1042ce6

Please sign in to comment.