Skip to content
This repository has been archived by the owner on Mar 29, 2018. It is now read-only.

Commit

Permalink
modified: app/models/asset.rb
Browse files Browse the repository at this point in the history
	modified:   app/models/directory_asset.rb
	modified:   app/models/file_asset.rb
	modified:   lib/directory_array.rb
	modified:   spec/controllers/admin/file_controller_spec.rb
	modified:   spec/views/admin/file/index.rhtml_spec.rb
  • Loading branch information
Sanath Kumar committed Aug 7, 2008
1 parent e668bf3 commit 7b6d36b
Show file tree
Hide file tree
Showing 6 changed files with 160 additions and 131 deletions.
1 change: 1 addition & 0 deletions app/models/asset.rb
Expand Up @@ -26,6 +26,7 @@ def rename(asset)
raise Errors, :modified unless Asset.find(@id, @version).exists?
new_asset = Pathname.new(File.join(@pathname.parent, @asset_name))
@pathname.rename(new_asset)
reset_directory_hash
@pathname = Pathname.new(new_asset)
@id = path2id(new_asset)
@version = AssetLock.new_lock_version
Expand Down
2 changes: 2 additions & 0 deletions app/models/directory_asset.rb
Expand Up @@ -15,6 +15,7 @@ def save
new_dir = Pathname.new(File.join(upload_location, @asset_name))
raise Errors, :modified unless AssetLock.confirm_lock(@version)
Dir.mkdir(new_dir)
reset_directory_hash
@id = path2id(new_dir)
@pathname = new_dir
@version = AssetLock.new_lock_version
Expand All @@ -34,6 +35,7 @@ def destroy
raise Errors, :illegal_path if (path.to_s == absolute_path or path.to_s.index(absolute_path) != 0)
raise Errors, :modified unless Asset.find(@id, @version).exists?
FileUtils.rm_r path, :force => true
reset_directory_hash
AssetLock.new_lock_version
return true
rescue Errors => e
Expand Down
2 changes: 2 additions & 0 deletions app/models/file_asset.rb
Expand Up @@ -20,6 +20,7 @@ def save
new_file = Pathname.new(File.join(upload_location, @asset_name))
raise Errors, :modified unless AssetLock.confirm_lock(@version)
File.open(new_file, 'wb') { |f| f.write(@uploaded_data.read) }
reset_directory_hash
@id = path2id(new_file)
@pathname = new_file
@version = AssetLock.new_lock_version
Expand All @@ -35,6 +36,7 @@ def destroy
raise Errors, :illegal_path if (path.to_s == absolute_path or path.to_s.index(absolute_path) != 0)
raise Errors, :modified unless Asset.find(@id, @version).exists?
path.delete
reset_directory_hash
AssetLock.new_lock_version
return true
rescue Errors => e
Expand Down
14 changes: 13 additions & 1 deletion lib/directory_array.rb
@@ -1,6 +1,11 @@
module DirectoryArray
attr_accessor :directory_hash, :lock_version

def get_directory_array(path)
path_str = path.to_s
@directory_hash = {} if @directory_hash.nil?
@lock_version = AssetLock.lock_version if @lock_version.nil?
return @directory_hash[path_str] if ( @directory_hash.has_key?(path_str) and AssetLock.confirm_lock(@lock_version))
asset_array = []
asset_absolute_path = Pathname.new(FileBrowserExtension.asset_path.to_s)
path.children.collect do |child|
Expand All @@ -13,9 +18,16 @@ def get_directory_array(path)
end
end
end
return asset_array.flatten
asset_array.flatten!
@directory_hash[path_str] = asset_array
@lock_version = AssetLock.lock_version
return asset_array
end

def reset_directory_hash
@directory_hash = {}
end

def hidden?(path)
path.realpath.basename.to_s =~ (/^\./)
end
Expand Down

0 comments on commit 7b6d36b

Please sign in to comment.