Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

nothing happens when using :absolute=>true option #15

Closed
movstox opened this Issue · 17 comments

2 participants

movstox Marc Schwieterman
movstox

hi,
i'm running mac os x, the latest ruby (2.0) and have this config working just fine

guard 'copy', {
:from => tmp1',
:to => 'tmp2',
:mkpath => true,
:delete => true,
:verbose => true,
:run_at_start => true
} do

puts "Starting to watch JavaScript files."
watch(%r{^.*\.js$})

end

but when i use absolute paths

guard 'copy', {
:from => '/Volumes/U3/ru-egogo/tmp1',
:to => '/Volumes/U3/ru-egogo/tmp2',
:mkpath => true,
:delete => true,
:verbose => true,
:absolute => true,
:run_at_start => true
} do

puts "Starting to watch JavaScript files."
watch(%r{^.*\.js$})

end

nothing happens. Am I doing something wrong?

Many thanks for your help.

Marc Schwieterman
Owner

Are you starting guard from somewhere not within the :from directory? I believe by default Guard only watches the directory that it's started in.

Does the --watchdir option fix the issue?

movstox

I'm starting guard and other processes using 'foreman start' from rails app directory and detection works just fine for other types of guards. What should i put as :from to monitor changes in Gemfile for instance?

With the following config

  guard 'copy', {
    :from => "/",   
    :to => "/Volumes/U3/ru-egogo", 
    :mkpath => true,
    :verbose => true,
    :delete=>true,
    :absolute=>true
  } 

I also get error ":to can't start from :from"

Marc Schwieterman
Owner

What's the absolute path of the rails app? If it's for example /home/user/someapp, then guard will only get file system notifications from within that directlry, and none of those would ever match /Volumes/U3/ru-egogo/tmp1.

The :to can't start with :from error is because a copy into a subdirectory of the :from directory would trigger a new file system notification, which would lead to another copy and this would loop forever.

movstox

Absolute path of the rails app is /Volumes/U3/ru-egogo.

Take a look at my first post, my point is that first configuration is working and the second doesn't.
I always run everything from the app's dir.

And it's still not clear how can i monitor files within my app's root dir (i.e. Gemfile) because absolute paths are not working for :from param and '/' for :from param gives an error..So i believe to reproduce it, it's enough to use absolute paths for both :from and :to params.

Let me know if i can help further on this.

Marc Schwieterman
Owner

What patch level of ruby 2.0 are you using?

I can reproduce the issue with 1.9.3, but ruby 2.0.0-p247 is crashing with no error on my system.

The :absolute option pertains to the :to option. This is mentioned in the README, albeit briefly. That feature was specifically added to copy project files into an appserver tmp directory as a sort of poor man's hot deploy. It's off by default to protect the user from accidentally clobbering files outside of the project they're currently working on.

I can probably fix this specific case, but any absolute path that would work without using the --watchdir option should be possible to express relatively, so I'm not sure that this would enable any new behavior.

I don't think there's any way to currently copy files in the root directory of the project. Is that something you need? It would probably be possible to treat . as a special case to support that, but I haven't looked at the matching code in a while.

movstox

I'm using ruby 2.0.0p247 (2013-06-27 revision 41674) [x86_64-darwin11.4.2]. Ok, it's clear for me that i shouldn't put absolute path into :to.

On files in the root directory case: I use your gem to sync rails app between my RamDisk (use memory disk) and hard drive. Basically, there're two important files I need to sync: Gemfile and .gitignore
Without this, I'll have to copy them manually from time to time. So currently i have ~99% of what I need.

I can live with that but if you think you can add some support for . as a special case or hidden directories like .git that would be nice. I wish that would be useful for someone else as well.

And thanks again for all your help and comments.

Marc Schwieterman marcisme referenced this issue from a commit
Marc Schwieterman support '.' for root directory in :from
It was not currently possible to watch the root directory of a project,
as raised in issue #15. This change adds a magic string value of '.' to
identify that everything from the root project down should be copied,
which requires no substitution in the target paths.
67be71b
Marc Schwieterman
Owner

Try out master and see if this works for you.

movstox

Thank you.

Mm..I pulled the latest gem from git via including gem 'guard-copy', :git =>'git://github.com/marcisme/guard-copy.git' into my Gemfile and tried 2 configs:

  guard 'copy', {
    :from => '.',   
    :to => '/Volumes/U3/ru-egogo/', 
    :mkpath => true,
    :verbose => true,
    :absolute=>true,
    :delete=>true
  } 

and

  guard 'copy', {
    :from => '.',   
    :to => '/Volumes/U3/ru-egogo', 
    :mkpath => true,
    :verbose => true,
    :absolute=>true,
    :delete=>true
  } 

Then I created a file, Gemfile2 inside my root directory. Nothing happened, i.e. new file was not detected. Maybe I'm doing something wrong.

Marc Schwieterman
Owner

What's the full path to the rails app?

Are any of the intermediate directories symlinks?

movstox

Ok, so I have Rails app at /Volumes/RamDisk/ru-egogo and want to make a backup to /Volumes/U3/ru-egogo.
Inside, there're regular directories without symlinks. Your patch, does it work for you under ruby 2.0?

Marc Schwieterman
Owner

This is more complicated than I originally thought. A couple of the watcher patterns will have to change too.

Marc Schwieterman
Owner

This should be working now. Can you try again?

movstox

Mmm...same thing for me.

Marc Schwieterman
Owner

Did you run bundle update guard-copy? You may still have the previous commit from master.

I've tried with 2.0.0, and copying into an existing directory is working for me. I did find a bug (investigating) where if the target directory doesn't exist, it copies the changed file to a file with that directory name, but it should work with an existing target directory.

marc@ret:/private/tmp/guard-copy
> ruby -v
ruby 2.0.0p247 (2013-06-27 revision 41674) [x86_64-darwin12.4.0]
marc@ret:/private/tmp/guard-copy
> cat Guardfile 
guard 'copy', {
  :from => '.',
  :to => '/tmp/guard-copy-copy',
  :mkpath => true,
  :verbose => true,
  :absolute => true
}
marc@ret:/private/tmp/guard-copy
> bundle exec guard
15:25:41 - INFO - Guard uses Tmux to send notifications.
15:25:41 - INFO - Guard uses TerminalTitle to send notifications.
15:25:41 - INFO - Guard::Copy - files in:
15:25:41 - INFO - .
15:25:41 - INFO - will be copied to:
15:25:41 - INFO - /tmp/guard-copy-copy
15:25:41 - INFO - Guard is now watching at '/private/tmp/guard-copy'
[1] guard(main)> 

marc@ret:/private/tmp/guard-copy
> ls ../guard-copy-copy/
marc@ret:/private/tmp/guard-copy
> touch foo

15:26:10 - INFO - copying to /tmp/guard-copy-copy
[1] guard(main)> 

marc@ret:/private/tmp/guard-copy
> ls ../guard-copy-copy/
foo
Marc Schwieterman
Owner

After having thought through this more, I don't think this approach is a good idea.

If copying from the root, the :to must be absolute, or you end up with the recursive copy situation again. So having a special value for :from is really just yet another option, but expressed in a different way, which is confusing and inconsistent with the current options. Looking back, I should have kept :from and :to as top-level options and passed everything else in an options hash to keep it separate.

I think the proper way to handle this would be to introduce yet another option for this special case, maybe :root. That's going to require thinking through its interaction with all the other options, and I unfortunately don't have enough free time to do that right now.

If you want to take a try at it, along with tests, a patch would be welcome. I'm sorry I couldn't be of more help.

Marc Schwieterman marcisme referenced this issue from a commit
Marc Schwieterman Revert root directory support via '.'
This was a bad idea, as explained in #15. It should have been implemented
as YAFO. (and in a feature branch)

This reverts commits:

67be71b
b02df2c
3590a5c
movstox

Ok, let's think on it. I'll get your code and see if I can be of any help on this. Thanks for your help.

Marc Schwieterman
Owner

No more work on this is planned at this time.

Marc Schwieterman marcisme closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.