Module: Watchit::FileSystem

Included in:
Injection, WatchitApp
Defined in:
lib/watchit/file_system.rb

Instance Method Summary collapse

Instance Method Details

#dir_mtime(dir_name) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/watchit/file_system.rb', line 3

def dir_mtime(dir_name)
  old_dir = Dir.pwd
  Dir.chdir dir_name

  # 最新修改时间
  lastest = Time.at(0)

  file_names = Dir.entries('.').select{|name| !name.start_with? '.'}
  file_names.each do |file_name|
    next if File.symlink? file_name # 忽略软连接

    # 普通文件
    if !File.directory?(file_name)
      mtime = File.mtime file_name
    # 目录
    else
      mtime = dir_mtime file_name
    end

    lastest = mtime if lastest < mtime
  end

  def lastest.serilize
    "#{self.year}/#{self.month}/#{self.day}/#{self.hour}/#{self.min}/#{self.sec}"
  end

  Dir.chdir old_dir
  return lastest
end