Permalink
Browse files

Prevent rake symlink generation task from fingerprinting existing fin…

…gerprint symlinks. Thanks to Evan Worley for contribution
  • Loading branch information...
1 parent 9db0a2f commit 0fd90f1d538af5903cfa9885db1cc592d9fb8868 @eliotsykes committed Jan 11, 2011
Showing with 31 additions and 6 deletions.
  1. +6 −2 lib/asset_fingerprint/asset.rb
  2. +25 −4 test/asset_test.rb
  3. BIN test/resources/test.gif
@@ -151,6 +151,10 @@ def symlinkable?
AssetFingerprint.asset_files_served_by_symlink?)
end
+ def self.fingerprint_symlink?(path)
+ File.symlink?(path) && File.basename(path) =~ FINGER_PRINTED_FILE_PATTERN
+ end
+
def self.generate_all_symlinks
AssetFingerprint.asset_paths.each do |source|
absolute_path = Asset.absolute_path(source)
@@ -164,14 +168,14 @@ def self.remove_all_symlinks(sources = nil)
sources.each do |source|
if File.directory?(source)
remove_all_symlinks(Dir.glob(File.join(source, "*")))
- elsif File.symlink?(source) && File.basename(source) =~ FINGER_PRINTED_FILE_PATTERN
+ elsif fingerprint_symlink?(source)
File.delete(source)
end
end
end
def self.generate_symlinks(path)
- if File.file?(path)
+ if File.file?(path) && !fingerprint_symlink?(path)
asset = Asset.create(path)
asset.build_symlink
elsif File.directory?(path)
View
@@ -4,15 +4,36 @@
class AssetTest < ActiveSupport::TestCase
def test_normalize_to_source_handles_arg_with_query_string
- path = '/path/to/foo-fp-12345678901234567890123456789012.png?mouseover=bar.png'
+ path = '/path/to/foo-fp-001abc78901234567890123456789012.png?mouseover=bar.png'
normalized = ::AssetFingerprint::Asset.normalize_to_source(path)
- assert_equal '/path/to/foo-fp-12345678901234567890123456789012.png', normalized
+ assert_equal '/path/to/foo-fp-001abc78901234567890123456789012.png', normalized
end
def test_normalize_to_source_handles_arg_without_query_string
- path = '/path/to/foo-fp-12345678901234567890123456789012.png'
+ path = '/path/to/foo-fp-001abc78901234567890123456789012.png'
normalized = ::AssetFingerprint::Asset.normalize_to_source(path)
- assert_equal '/path/to/foo-fp-12345678901234567890123456789012.png', normalized
+ assert_equal '/path/to/foo-fp-001abc78901234567890123456789012.png', normalized
+ end
+
+ def test_fingerprint_symlink_returns_true_for_fingerprint_symlink
+ fingerprinted_path = 'test/resources/test-fp-002abc78901234567890123456789012.gif'
+ FileUtils.ln_sf('test/resources/test.gif', fingerprinted_path)
+ assert ::AssetFingerprint::Asset.fingerprint_symlink?(fingerprinted_path)
+ File.delete(fingerprinted_path)
+ end
+
+ def test_fingerprint_symlink_returns_false_for_non_symlink_file_with_fingerprint_like_filename
+ path = 'test/resources/foo-fp-003abc78901234567890123456789012.css'
+ FileUtils.touch(path)
+ assert !(::AssetFingerprint::Asset.fingerprint_symlink?(path))
+ File.delete(path)
+ end
+
+ def test_fingerprint_symlink_returns_false_for_symlink_with_non_fingerprint_like_filename
+ symlink_path = 'test/resources/symlink-to-test.gif'
+ FileUtils.ln_sf('test/resources/test.gif', symlink_path)
+ assert !(::AssetFingerprint::Asset.fingerprint_symlink?(symlink_path))
+ File.delete(symlink_path)
end
end
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 0fd90f1

Please sign in to comment.