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

Change order of include / exclude #16

Closed
wants to merge 1 commit into from
Closed

Conversation

kfiku
Copy link

@kfiku kfiku commented Aug 5, 2013

Now we can't use somethink like this:

rsync src dest --include=*/ --include=*.js --exclude=* -av

to sync only *.js" files, becouse order is first exclude, include.

Now we can't use somethink like this:
```
rsync src dest --include=*/ --include=*.js --exclude=* -av
```
to sync only *.js" files, becouse order is first exclude, include.
@jedrichards
Copy link
Owner

Sorry for delay, thanks for your input, but what if some users are relying on the current order? i.e. something like,

rsync src dest --exclude=*.foo --include=keep.foo  -av

to exclude all .foo but keep keep.foo? They would suddenly find their scripts broken if we made this change and they upgraded, right?

If you need different behaviour it might be better to just use the args option to get what you need?

@kfiku
Copy link
Author

kfiku commented Sep 10, 2013

http://unix.stackexchange.com/questions/76237/rsync-certain-files-excluding-the-rest-ignoring-svn-directory-recursively here you have example what I meen.
This how works rsync command, is you want copy/sync you need first --include '*/' - to "wach all files" next specify extentions to copy/rsync --include='*.php' and next exclude all other extentions --exclude='*'

@jedrichards
Copy link
Owner

But the problem is if I reverse the order now it could likely break some people's scripts who were relying on exclude coming before include when they update with npm. You can achieve what you want right now with something like:

{
    src: "src",
    dest: "dest",
    args: ["--include=*/","--include=*.js","--exclude=*","-av"]
}

I agree it might have been better to have include come before exclude, but that's the way it is, and I don't want to change something fundamental now ...

@juriejan
Copy link
Contributor

juriejan commented Mar 6, 2014

I'm not sure, but it seems to me that the sample given before by @jedrichards does not work I'd expect it to. The following command excludes all *.foo files, but does not include keep.foo:

rsync src dest --exclude=*.foo --include=keep.foo -av

I order to keep keep.foo the order has to be swapped:

rsync src dest --include=keep.foo --exclude=*.foo -av

Am I missing something here?

@jedrichards
Copy link
Owner

You're right, if you want to exclude *.foo but keep keep.foo you have to have a command like:

rsync src dest --include=keep.foo --exclude=*.foo -av

But the problem is that rsyncwrapper by default builds its command with the --exclude options coming first (like in your example above that doesn't work as expected).

If you want rsyncwrapper to be build a command that works in this way you have to specify the includes/excludes explicitly in the args array to maintain the order. So an options object that looks like:

{
    src: "src",
    dest: "dest",
    args: ["--include=keep.foo","--exclude=*.foo","-av"]
}

I might change this in a future update ...

@juriejan
Copy link
Contributor

juriejan commented Mar 6, 2014

I see now that I was also very narrowly minded assuming that the second scenario I mentioned was the most common one. I'll be using my own branch till a change is made.

I have an idea of an implementation that would allow people to mix includes and excludes which ever way they like. You could perhaps just have one single array that contains strings that correspond to the exclude/include file format. Here's an example:

{
    exclude: ['+keep.foo', '-*.foo']
}

Doesn't seem too solid to me, but due to the fact that rsync users might be familiar with it I think it could be acceptable. What do you think? I'd be happy to take a shot at implementing it.

@kfiku kfiku deleted the patch-1 branch March 6, 2014 19:40
@kfiku kfiku restored the patch-1 branch March 6, 2014 19:40
@kfiku kfiku deleted the patch-1 branch March 6, 2014 19:40
@jedrichards
Copy link
Owner

Yeah, I was thinking it would be nice to try and have some concise syntax where people could easily define some complex exclude/include options and maintain whichever order was appropriate for their case.

At the moment having rsyncwrapper decide the order is not too good :S

If you fancy having a go at implementing it then please go ahead!

Perhaps we could name the option something like includeExclude to make it clear it does both things?

{
    includeExclude: ['+keep.foo', '-*.foo']
}

@juriejan
Copy link
Contributor

juriejan commented Mar 7, 2014

That sounds good. I'll give it a shot.

On a side note: Can you give me an example of when it would be useful to have exclude before the include argument?

It seems to me that with using include before exclude allows you to pretty much do anything you'd like to, and that having it the other way around is essentially useless.

By default all files in the source are included, then you choose what to exclude, and then you override the exclude in certain places. It's not like you'd ever be indicating what you'd like to include and then what you'd like to exclude.

@jedrichards
Copy link
Owner

Humm. You might be right. I was naively assuming that since include before exclude was a valid pattern, then the opposite must be true too. But reading a bit more about it, and searching the web, it seems you're right - exclude before include would never really achieve anything.

So maybe the change should be to just put includes before excludes, bump the minor package version, mention it in the readme and leave it there?

Or do you think there's still value in combining them into one option?

@juriejan
Copy link
Contributor

juriejan commented Mar 7, 2014

I'd say let's just swap them and carry on till someone else asks for the discussed functionality. I certainly won't be needing it soon.

@jedrichards
Copy link
Owner

OK that's in and published to 0.3.0. Thanks @juriejan. Also thanks @kfiku ... you were right all along, sorry :)

@kfiku
Copy link
Author

kfiku commented Mar 7, 2014

no problem :) but i think wrote here is enough to work with it

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.

3 participants