Skip to content

Commit

Permalink
Merge pull request #579 from lostapathy/file_store_error_checking
Browse files Browse the repository at this point in the history
make sure `rake clobber_assets` and FileStore#clear work when cache dir doesn't exist
  • Loading branch information
rafaelfranca authored Sep 26, 2018
2 parents 06160d0 + af1e5ab commit e25e0f5
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/sprockets/cache/file_store.rb
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,10 @@ def inspect
#
# Returns true
def clear(options=nil)
root_dirs = Dir.entries(@root).reject { |f| (EXCLUDED_DIRS + GITKEEP_FILES).include?(f) }
FileUtils.rm_r(root_dirs.collect{ |f| File.join(@root, f) })
if File.exist?(@root)
root_dirs = Dir.entries(@root).reject { |f| (EXCLUDED_DIRS + GITKEEP_FILES).include?(f) }
FileUtils.rm_r(root_dirs.collect{ |f| File.join(@root, f) })
end
true
end

Expand Down
7 changes: 7 additions & 0 deletions test/test_cache_store.rb
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,13 @@ def test_corrupted_read
refute @_store.get("corrupt")
end

def test_clear_store_dir_not_exist
@cache_dir = File.join(Dir::tmpdir, 'sprockets')
refute File.exist?(@cache_dir)
@store = Sprockets::Cache::FileStore.new(@cache_dir)
assert @store.clear
end

include CacheStoreTests
end

Expand Down
8 changes: 8 additions & 0 deletions test/test_manifest.rb
Original file line number Diff line number Diff line change
Expand Up @@ -672,4 +672,12 @@ def call(_)
Sprockets::Manifest.new(@env, @dir).compile('logo.png', 'troll.png')
assert_equal %w(0 1 0 1), processor.seq
end

test 'clobber works when cache_dir not created' do
@cache_dir = File.join(Dir::tmpdir, 'sprockets')
refute File.exist?(@cache_dir)
@env.cache = Sprockets::Cache::FileStore.new(@cache_dir)
manifest = Sprockets::Manifest.new(@env, File.join(@dir, 'manifest.json'))
manifest.clobber
end
end

0 comments on commit e25e0f5

Please sign in to comment.