lib/vfs/storages/hash_fs.rb in vfs-0.1.0 vs lib/vfs/storages/hash_fs.rb in vfs-0.1.1

- old
+ new

@@ -1,7 +1,7 @@ # -# Dirty and uneficient In Memory FS, mainly for tests. +# Very dirty and uneficient In Memory FS, mainly for tests. # module Vfs module Storages class HashFs < Hash def initialize @@ -96,11 +96,11 @@ # def move_dir path # raise 'not supported' # end - def each path, &block + def each_entry path, &block base, name = split_path path assert cd(base)[name], :include?, :dir cd(base)[name].each do |relative_name, content| next if relative_name.is_a? Symbol if content[:dir] @@ -109,30 +109,50 @@ block.call relative_name, :file end end end - def efficient_dir_copy from, to + def efficient_dir_copy from, to, override from.storage.open_fs do |from_fs| to.storage.open_fs do |to_fs| if from_fs == to_fs for_spec_helper_effective_copy_used - from_base, from_name = split_path from.path - assert cd(from_base)[from_name], :include?, :dir - - to_base, to_name = split_path to.path - assert_not cd(to_base), :include?, to_name - - cd(to_base)[to_name] = cd(from_base)[from_name] - + _efficient_dir_copy from.path, to.path, override true else false end end end - end + end + + def _efficient_dir_copy from_path, to_path, override + from_base, from_name = split_path from_path + assert cd(from_base)[from_name], :include?, :dir + + to_base, to_name = split_path to_path + # assert_not cd(to_base), :include?, to_name + + if cd(to_base).include? to_name + if cd(to_base)[to_name][:dir] + each_entry from_path do |name, type| + if type == :dir + _efficient_dir_copy "#{from_path}/#{name}", "#{to_path}/#{name}", override + else + raise "file #{to_path}/#{name} already exist!" if cd(to_base)[to_name].include?(name) and !override + cd(to_base)[to_name][name] = cd(from_base)[from_name][name].clone + end + end + else + raise "can't copy dir #{from_path} to file #{to_path}!" + end + else + cd(to_base)[to_name] = {dir: true} + _efficient_dir_copy from_path, to_path, override + end + end + protected :_efficient_dir_copy def for_spec_helper_effective_copy_used; end # def upload_directory from_local_path, to_remote_path # FileUtils.cp_r from_local_path, to_remote_path # end \ No newline at end of file