lib/buildmaster/cotta/in_memory_system.rb in BuildMaster-1.0.9 vs lib/buildmaster/cotta/in_memory_system.rb in BuildMaster-1.1.9
- old
+ new
@@ -43,16 +43,16 @@
return !content.nil? && content.file?
end
def dir_stat(pathname)
check_dir_exists(pathname)
- ContentStat.new(path_content(pathname))
+ path_content(pathname).stat
end
def file_stat(pathname)
check_file_exists(pathname)
- ContentStat.new(path_content(pathname))
+ path_content(pathname).stat
end
def list(pathname)
check_dir_exists(pathname)
content = path_content(pathname)
@@ -165,10 +165,13 @@
if (options =~ /r/)
raise Errno::ENOENT.new(pathname)
end
file_content = create_file(pathname)
end
+ if (options =~ /w/)
+ file_content.touch
+ end
return file_content
end
def delete_entry(pathname)
@file_system.delete pathname
@@ -176,15 +179,16 @@
end
end
class DirectoryContent
- attr_reader :name, :children
+ attr_reader :name, :children, :stat
def initialize(name)
@name = name
@children = Array.new
+ @stat = ContentStat.new(self)
end
def file?
return false
end
@@ -207,16 +211,17 @@
system.copy_dir(source_path, target_path)
end
end
class FileContent
- attr_reader :name, :content
+ attr_reader :name, :content, :stat
attr_writer :content
def initialize(name)
@name = name
@content = ''
+ @stat = ContentStat.new(self)
end
def file?
return true
end
@@ -232,15 +237,22 @@
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
+
+ def touch
+ @stat.touch
+ end
end
class ContentStat
+ attr_reader :mtime
+
def initialize(content)
@content = content
+ @mtime = Time.new
end
def mode
'10777'
end
@@ -253,8 +265,20 @@
@content.file?
end
def directory?
@content.directory?
+ end
+
+ def touch
+ @mtime = Time.new
+ end
+
+ def writable?
+ true
+ end
+
+ def <=> stat
+ mtime <=> stat.mtime
end
end
end
\ No newline at end of file