lib/buildmaster/cotta/in_memory_system.rb in BuildMaster-1.0.6 vs lib/buildmaster/cotta/in_memory_system.rb in BuildMaster-1.0.9

- old
+ new

@@ -41,14 +41,33 @@ def file_exists?(pathname) content = path_content(pathname) return !content.nil? && content.file? end + def dir_stat(pathname) + check_dir_exists(pathname) + ContentStat.new(path_content(pathname)) + end + + def file_stat(pathname) + check_file_exists(pathname) + ContentStat.new(path_content(pathname)) + end + def list(pathname) + check_dir_exists(pathname) content = path_content(pathname) return content.children.collect {|item| item.name} end + + def check_dir_exists(pathname) + raise Errno::ENOENT, pathname unless dir_exists? pathname + end + + def check_file_exists(pathname) + raise Errno::ENOENT, pathname unless file_exists? pathname + end def mkdir(pathname) path_content!(pathname.cotta_parent).add(create_dir(pathname)) end @@ -74,10 +93,11 @@ copy(source, target) delete_file(source) end def copy_dir(source, target) + check_dir_exists(source) mkdir(target) path_content(source).children.each do |item| item.copy_to_dir(self, source, target) end end @@ -203,12 +223,38 @@ def directory? return false end + def size + content.size + end + def copy_to_dir(system, parent_dir, target_dir) target_path = target_dir.join(name) source_path = parent_dir.join(name) system.copy_file(source_path, target_path) end -end +end + +class ContentStat + def initialize(content) + @content = content + end + + def mode + '10777' + end + + def size + @content.size + end + + def file? + @content.file? + end + + def directory? + @content.directory? + end +end end \ No newline at end of file