Skip to content

Commit

Permalink
check parent paths for .ipfsignore files
Browse files Browse the repository at this point in the history
fix ipfs add to ensure that we are checking parent paths for
appropriate .ipfsignore files

[ reworded to conform to commit msg guidelines ]
  • Loading branch information
gatesvp committed May 14, 2015
1 parent 153886e commit 500e756
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions core/commands/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,15 @@ remains to be implemented.
return
}

rootnd, err := addFile(n, file, outChan, progress, wrap, hidden, ignoreFilePatterns)
// If the file is not a folder, then let's get the root of that
// folder and attempt to load the appropriate .ipfsignore.
localIgnorePatterns := ignoreFilePatterns
if !file.IsDirectory() {
parentPath := path.Dir(file.FileName())
localIgnorePatterns = checkForLocalIgnorePatterns(parentPath, ignoreFilePatterns)
}

rootnd, err := addFile(n, file, outChan, progress, wrap, hidden, localIgnorePatterns)
if err != nil {
res.SetError(err, cmds.ErrNormal)
return
Expand Down Expand Up @@ -299,7 +307,7 @@ func addDir(n *core.IpfsNode, dir files.File, out chan interface{}, progress boo
log.Infof("adding directory: %s", dir.FileName())

// Check for an .ipfsignore file that is local to this Dir and append to the incoming
localIgnorePatterns := checkForLocalIgnorePatterns(dir, ignoreFilePatterns)
localIgnorePatterns := checkForLocalIgnorePatterns(dir.FileName(), ignoreFilePatterns)

for {
file, err := dir.NextFile()
Expand Down Expand Up @@ -344,17 +352,17 @@ func addDir(n *core.IpfsNode, dir files.File, out chan interface{}, progress boo
return tree, nil
}

func checkForLocalIgnorePatterns(dir files.File, ignoreFilePatterns []ignore.GitIgnore) []ignore.GitIgnore {
func checkForLocalIgnorePatterns(dir string, ignoreFilePatterns []ignore.GitIgnore) []ignore.GitIgnore {
var ignorePathname string
if dir.FileName() == "." {
if dir == "." {
ignorePathname = ".ipfsignore"
} else {
ignorePathname = path.Join(dir.FileName(), ".ipfsignore")
ignorePathname = path.Join(dir, ".ipfsignore")
}

localIgnore, ignoreErr := ignore.CompileIgnoreFile(ignorePathname)
if ignoreErr == nil && localIgnore != nil {
log.Debugf("found ignore file: %s", dir.FileName())
log.Debugf("found ignore file: %s", dir)
return append(ignoreFilePatterns, *localIgnore)
} else {
return ignoreFilePatterns
Expand Down

0 comments on commit 500e756

Please sign in to comment.