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
32
33
34
|
# File 'lib/fake_dropbox/utils.rb', line 5
def metadata(path, list=false)
full_path = File.join(@dropbox_dir, path)
path.insert(0, '/') if path[0] != '/'
bytes = File.directory?(path) ? 0 : File.size(full_path)
metadata = {
thumb_exists: false,
bytes: bytes,
modified: File.mtime(full_path).strftime(DATE_FORMAT),
path: path,
is_dir: File.directory?(full_path),
size: "#{bytes} bytes",
root: "dropbox"
}
if File.directory?(full_path)
metadata[:icon] = "folder"
if list
entries = Dir.entries(full_path).reject { |x| ['.', '..'].include? x }
metadata[:contents] = entries.map do |entry|
metadata(File.join(path, entry))
end
end
else
metadata[:icon] = "page_white"
end
metadata
end
|