Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ignore and hidden file support to add #1448

Closed
wants to merge 0 commits into from
Closed

Conversation

gatesvp
Copy link
Contributor

@gatesvp gatesvp commented Jul 6, 2015

#653 support, attempt number 4.

License: MIT
Signed-off-by: Gaetan Voyer-Perrault gatesvp@gmail.com

@jbenet jbenet added the backlog label Jul 6, 2015

fName := filepath.Base(f.FileName())

if strings.HasPrefix(fName, ".") && len(fName) > 1 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this may capture .. but not .. is that intended? (maybe dont want it for either?)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So I'm assuming that filepath.Base(f.FileName()) will wipe out any instance of the "double dot" because we're just looking at the last element of the Path. http://golang.org/pkg/path/filepath/#Base

According to the docs, we only get a file name or a "single dot" for an empty path, hence the len(fName) > 1 check.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sounds good 👍

@jbenet
Copy link
Member

jbenet commented Jul 6, 2015

@gatesvp this LGTM! i'll give one more pass manually (playing with it) to see if there's any major UX flaws, and merge. thank you very much for all the work on this changeset. it will be very useful to tons of people! \o/

@jbenet
Copy link
Member

jbenet commented Jul 6, 2015

Hey @gatesvp am i doing something wrong?

> tree -a
.
├── .a
├── .b
├── .ipfsignore
├── a
├── aa
│   ├── a
│   └── b
├── b
└── bb
    ├── .ipfsignore
    ├── a
    └── b

2 directories, 10 files
> cat .ipfsignore
b
> cat bb/.ipfsignore
a
> ipfs add -r bb
added QmZULkCELmmk5XNfCgTnCyFgAVxBRBXyDHGGMVoLFLiXEN bb/a
added QmZULkCELmmk5XNfCgTnCyFgAVxBRBXyDHGGMVoLFLiXEN bb/b
added QmUvbZ6woqqny4kMTWYwH5Y7Rs2KwGnHYAwLt5DV9HKuZG bb
> echo "should have not added bb/a"
should have not added bb/a
> echo "(maybe) should have not added bb/b"
(maybe) should have not added bb/b
> ipfs add -r .
added QmZULkCELmmk5XNfCgTnCyFgAVxBRBXyDHGGMVoLFLiXEN a
added QmZULkCELmmk5XNfCgTnCyFgAVxBRBXyDHGGMVoLFLiXEN aa/a
added QmZULkCELmmk5XNfCgTnCyFgAVxBRBXyDHGGMVoLFLiXEN aa/b
added QmUvbZ6woqqny4kMTWYwH5Y7Rs2KwGnHYAwLt5DV9HKuZG aa
added QmZULkCELmmk5XNfCgTnCyFgAVxBRBXyDHGGMVoLFLiXEN b
added QmZULkCELmmk5XNfCgTnCyFgAVxBRBXyDHGGMVoLFLiXEN bb/a
added QmZULkCELmmk5XNfCgTnCyFgAVxBRBXyDHGGMVoLFLiXEN bb/b
added QmUvbZ6woqqny4kMTWYwH5Y7Rs2KwGnHYAwLt5DV9HKuZG bb
added QmP3bmqWiPux3qRdEVJZhe12sYqJgqa2HoCCaKCQPfCjpH .
> echo "(maybe) should have not added aa/b"
(maybe) should have not added aa/b
> echo "should have not added ./b"
should have not added ./b

@gatesvp
Copy link
Contributor Author

gatesvp commented Jul 6, 2015

hmmm... it's not matching the exact folder name? There's no test for the scenario of an ignore file that exactly matches a folder name.

Let me add/run this test (after I sleep) and see if I can't figure out what we're missing? I suspect that addDir may be missing a check for ignoreFiles because I'm checking the children but not the folder itself.

@jbenet
Copy link
Member

jbenet commented Jul 6, 2015

hmmm... it's not matching the exact folder name? There's no test for the scenario of an ignore file that exactly matches a folder name.

it's not skipping ignored files. added but shouldn't have been:

aa/b # should ignore "b" (parent)
b    # should ignore "b"
bb/a # should ignore "a"
bb/b # should ignore "b" (parent)

@gatesvp
Copy link
Contributor Author

gatesvp commented Jul 7, 2015

So I have my brain back and here's my test:

mkdir -p temp &&
cd temp &&
echo "blah" > .a &&
echo "blah" > .b &&
echo "b" > .ipfsignore &&
echo "blah" > a &&
echo "blah" > b &&
mkdir aa &&
echo "blah" > aa/a &&
echo "blah" > aa/b &&
mkdir bb &&
echo "blah" > bb/a &&
echo "blah" > bb/b &&
echo "a" > bb/.ipfsignore &&
ipfs add -r .

That should resemble your tree structure above. My output is

added QmfM9ic5LJj7V6ecozFx1MkSoaaiq3PXfhJoFvyqzpLXSf a
added QmfM9ic5LJj7V6ecozFx1MkSoaaiq3PXfhJoFvyqzpLXSf aa/a
added QmcjpKziyj7YeFWztxXsjR8npDyi5WSfzz3sjPMLZ4k7nw aa
added QmQDngQu2bWLFDqmKGUQCbde2VfeCNZYsVsNmim1Pxz7Ke .

So it actually ignored the bb folder. Doing ipfs add -r bb actually returned the "ignored" error message. If I step into the bb folder and do the recursive add it correctly ignore both the a and b file within the bb folder.

So it's all working as expected on Linux box. Is there a possible configuration issue here?

@jbenet
Copy link
Member

jbenet commented Jul 7, 2015

in osx, with your branch, i get:

> mkdir -p temp && \
cd temp && \
echo "blah" > .a && \
echo "blah" > .b && \
echo "b" > .ipfsignore && \
echo "blah" > a && \
echo "blah" > b && \
mkdir aa && \
echo "blah" > aa/a && \
echo "blah" > aa/b && \
mkdir bb && \
echo "blah" > bb/a && \
echo "blah" > bb/b && \
echo "a" > bb/.ipfsignore && \
ipfs add -r .
added QmfM9ic5LJj7V6ecozFx1MkSoaaiq3PXfhJoFvyqzpLXSf a
added QmfM9ic5LJj7V6ecozFx1MkSoaaiq3PXfhJoFvyqzpLXSf aa/a
added QmfM9ic5LJj7V6ecozFx1MkSoaaiq3PXfhJoFvyqzpLXSf aa/b
added QmbU4K1QsoFqnVZB8VZEJ9qdNXn14N2xNj227s24LoAYev aa
added QmfM9ic5LJj7V6ecozFx1MkSoaaiq3PXfhJoFvyqzpLXSf b
added QmfM9ic5LJj7V6ecozFx1MkSoaaiq3PXfhJoFvyqzpLXSf bb/a
added QmfM9ic5LJj7V6ecozFx1MkSoaaiq3PXfhJoFvyqzpLXSf bb/b
added QmbU4K1QsoFqnVZB8VZEJ9qdNXn14N2xNj227s24LoAYev bb
added QmcVAngmQaxmTrFQLC4K2aQAWtoooB473W2osMgJPKXzC8 .

in linux, i get:

mkdir -p temp && cd temp && echo "blah" > .a && echo "blah" > .b && echo "b" > .ipfsignore && echo "blah" > a && echo "blah" > b && mkdir aa && echo "blah" > aa/a && echo "blah" > aa/b && mkdir bb && echo "blah" > bb/a && echo "blah" > bb/b && echo "a" > bb/.ipfsignore && ipfs add -r .
added QmfM9ic5LJj7V6ecozFx1MkSoaaiq3PXfhJoFvyqzpLXSf a
added QmfM9ic5LJj7V6ecozFx1MkSoaaiq3PXfhJoFvyqzpLXSf aa/a
added QmfM9ic5LJj7V6ecozFx1MkSoaaiq3PXfhJoFvyqzpLXSf aa/b
added QmbU4K1QsoFqnVZB8VZEJ9qdNXn14N2xNj227s24LoAYev aa
added QmfM9ic5LJj7V6ecozFx1MkSoaaiq3PXfhJoFvyqzpLXSf b
added QmfM9ic5LJj7V6ecozFx1MkSoaaiq3PXfhJoFvyqzpLXSf bb/a
added QmfM9ic5LJj7V6ecozFx1MkSoaaiq3PXfhJoFvyqzpLXSf bb/b
added QmbU4K1QsoFqnVZB8VZEJ9qdNXn14N2xNj227s24LoAYev bb
added QmcVAngmQaxmTrFQLC4K2aQAWtoooB473W2osMgJPKXzC8 .

So it's all working as expected on Linux box. Is there a possible configuration issue here?

bizarre. wait, is there anything in need to do to the config? no, right? just build + install with gatesvp:master

@jbenet
Copy link
Member

jbenet commented Jul 7, 2015

Aha! Found the problem.

Try it with the daemon on 😄

@jbenet
Copy link
Member

jbenet commented Jul 7, 2015

To be clear, without the daemon, i got the expected:

added QmfM9ic5LJj7V6ecozFx1MkSoaaiq3PXfhJoFvyqzpLXSf a
added QmfM9ic5LJj7V6ecozFx1MkSoaaiq3PXfhJoFvyqzpLXSf aa/a
added QmcjpKziyj7YeFWztxXsjR8npDyi5WSfzz3sjPMLZ4k7nw aa
added QmQDngQu2bWLFDqmKGUQCbde2VfeCNZYsVsNmim1Pxz7Ke .

rootnd, err := addFile(n, file, outChan, progress, wrap, trickle)
// If the file is not a folder, then let's get the root of that
// folder and attempt to load the appropriate .ipfsignore.
localIgnorePatterns := checkForParentIgnorePatterns(file.FileName(), ignoreFilePatterns)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the problem is that -- doing this here, in the Run function, means it's getting executed in the daemon with the daemon chdir.

we need to do all this part (the ignores) before hand, in the PreRun (or in the cmdslib? maybe the cmdslib needs an option to be given a function like os.Walk that decides whether to add files or not -- that way we can implement support for .ipfsignore outside the cmdslib)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the ignore logic should really go in commands/files

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the hidden logic should be fine to stay here though, we encode the files attributes and send them over. But the enumeration of which files to add is done in either commands/cli/parse or commands/files, namely the serialFile struct (i think) which is basically a directory and when NextFile is called on it, it will return the next item under it...

This change is more difficult than I first thought it would be...

@whyrusleeping
Copy link
Member

👍 to moving all the misc parameters into a struct. Makes things a tad cleaner.

@whyrusleeping whyrusleeping removed their assignment Jul 7, 2015
@jbenet
Copy link
Member

jbenet commented Jul 8, 2015

@whyrusleeping we had the unfortunate discovery that this needs to change the cmdslib. do you think we should get rid of some of the File abstractions and use an os.Walk? could you take a look @whyrusleeping and lmk how much effort it may be?

jbenet added a commit that referenced this pull request Jul 9, 2015
this test fails .ipfsignore - only with daemon on. See:
#1448

License: MIT
Signed-off-by: Juan Batiz-Benet <juan@benet.ai>
@jbenet
Copy link
Member

jbenet commented Jul 9, 2015

I split this PR into two parts:

@whyrusleeping
Copy link
Member

@jbenet I think it may be worthwhile to use the os.Walk instead of the files abstraction. It's gonna be a moderate amount of work to do the refactor, and we will have to figure out how to deal with input from stdin. But the increased (hopefully) simplicity will be well worth it IMO

@jbenet
Copy link
Member

jbenet commented Jul 15, 2015

@jbenet I think it may be worthwhile to use the os.Walk instead of the files abstraction. It's gonna be a moderate amount of work to do the refactor, and we will have to figure out how to deal with input from stdin. But the increased (hopefully) simplicity will be well worth it IMO

@whyrusleeping i agree.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants