public
Description: The Rails Engines plugin
Homepage: http://rails-engines.org
Clone URL: git://github.com/lazyatom/engines.git
Added a fix for absolute paths being created into plugin_assets directory. [#6 
state:resolved], [#26 state:resolved] - apologies for the delay, and thanks to 
Azimux for the patch.
lazyatom (author)
Fri Oct 24 04:20:34 -0700 2008
commit  031d8c1902c117b4e51f249857f150386caee4ae
tree    127ff587ba3abfdcca855faff97d1dac97c9d625
parent  5cbfd7d4d95fc0299e9d255aee3ce14d5b3f2976
...
144
145
146
147
 
148
149
150
...
144
145
146
 
147
148
149
150
0
@@ -144,7 +144,7 @@ module Engines
0
       source_files -= source_dirs
0
       
0
       unless source_files.empty?
0
-        base_target_dir = File.join(destination, File.dirname(source_files.first))
0
+        base_target_dir = File.join(destination, File.dirname(source_files.first).gsub(source, ''))
0
         FileUtils.mkdir_p(base_target_dir)
0
       end
0
       
...
24
25
26
 
 
 
 
27
28
29
...
24
25
26
27
28
29
30
31
32
33
0
@@ -24,6 +24,10 @@ class AssetsTest < Test::Unit::TestCase
0
     assert File.exist?(File.join(Engines.public_directory, 'test_assets', 'subfolder', 'file_in_subfolder.txt'))
0
   end
0
   
0
+  def test_engines_has_not_created_duplicated_file_structure
0
+    assert !File.exists?(File.join(Engines.public_directory, "test_assets", RAILS_ROOT))
0
+  end
0
+  
0
   def test_public_files_have_been_copied_from_test_assets_with_assets_dir_plugin
0
     Engines::Assets.mirror_files_for Engines.plugins[:test_assets_with_assets_directory]
0
 

Comments

ioquatix Mon Oct 27 14:24:33 -0700 2008

I have to ask the question, what is the point of this code anyway? I couldn’t understand why it is there. The directory is created anyway, further down in that function. Are you able to fill me in on what this is about?

Knack Tue Oct 28 02:20:45 -0700 2008

I think the only situation when this code is necessary is when you have an “assets” dir with files but no subdirectories (source_dirs is empty). In this case, the first block will take care of creating the destination dir.

I suppose the block could be replaced by:

FileUtils.mkdir_p(destination)

Anyway, I haven’t tested it.

ioquatix Tue Oct 28 22:45:01 -0700 2008

Okay, I see – thanks for explaining that. I’ve never actually seen the case when there are files in the root directory, however it might exist.

azimux Tue Oct 28 23:21:28 -0700 2008

I also didn’t see the point of this code. Originally I fixed this by removing that code, and this worked with no problems at all in all of my projects. I was going to submit this as the patch at first, but when I wrote the test for it, it failed some other test. I put it back in and changed it to the patch I submitted and then all the tests passed. I didn’t feel like figuring out why that other test was failing at the time. I probably should have recorded which one it was. But you can probably figure it out by deleting the code and running the tests.

lazyatom Thu Oct 30 07:27:13 -0700 2008

Azimux – would you mind re-finding what broke?

The reason I added this was because the patch came with a test that indeed failed, and I saw the absolute path directory being created. So, I was happy to apply the fix, given it passed the tests.

In general, I’m not hugely happy with the implementation of this whole chunk of the plugin. I would welcome a cleaner, clearer rewrite of this that we can merge back in.