Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #9136 (closed defect: fixed)

Opened 1 year ago

Last modified 7 months ago

Layouts in symlinked dirs are not found

Reported by: caio Assigned to: core
Priority: normal Milestone: 2.x
Component: ActionPack Version: edge
Severity: normal Keywords:
Cc:

Description

  1. Create a controller with a module: Foo::BarController
  2. Create a directory anywhere: ~/foo
  3. symlink that dir to app/views/layouts/foo in your app
  4. In thar dir, put a layout file with some noticeable content and a detectable name: bar.html.erb

expected: the layout file to be found regardlessly of being in a symlinked or real dir.

observed: layout is not found.

This is because Dir::glob does not traverse symlinks, so the layout_list method fails to locate the files.

This can be patched by traversing the symlinks manually. Here's how I redefined the layout_list method:

def layout_list(path = nil) #:nodoc:
  return view_paths.map{ |view_path| layout_list(view_path) }.flatten if path.nil?
  Dir["#{path}/**/*"].inject([]) do |r, path|
    r << path
    r += layout_list(path) if File.symlink? path
    r
  end
end

All AP tests pass with this change. I have plans to make a test case, but don't have the time right now. If anyone feels like jumping in...

Attachments

9136_r7250.diff (0.8 kB) - added by caio on 07/30/07 05:59:19.
patch
fix_symlinked_view_paths.diff (4.1 kB) - added by court3nay on 03/28/08 19:17:00.

Change History

07/30/07 05:59:19 changed by caio

  • attachment 9136_r7250.diff added.

patch

07/30/07 12:53:36 changed by manfred

  • status changed from new to closed.
  • resolution set to untested.

Thanks for your patch. I'm closing this as untested until you or someone else finds the time to write tests. Please reopen the ticket when you have tests.

01/29/08 10:12:37 changed by court3nay

  • status changed from closed to reopened.
  • resolution deleted.
  • milestone changed from 1.x to 2.x.

I don't have a patch, but this has started occurring in edge rails again.

03/28/08 18:27:09 changed by court3nay

Changing all instances of Dir.glob with "**/**/b" will traverse symlinks. Investigating further...

03/28/08 19:15:43 changed by court3nay

I meant of course "**/*/**". duh.

anyway, here's the fix. hopefully people aren't relying on the behavior of **/

03/28/08 19:17:00 changed by court3nay

  • attachment fix_symlinked_view_paths.diff added.

03/28/08 20:54:30 changed by bitsweat

  • status changed from reopened to closed.
  • resolution set to fixed.

(In [9120]) Fix layouts in symlinked paths. Closes #9136 [court3nay, caio]

03/30/08 12:34:27 changed by kamal

This broke the query_reviewer plugin which puts its templates in vendor/plugins/query_reviewer/lib/query_reviewer/views/ (@@processed_view_paths will list the template files as they are directly under the views directory).

Are there other ways to traverse symlinks?

03/30/08 13:36:47 changed by kamal

Sorry, I meant @@processed_view_paths will not list the template files