5 $server = Couch::Server.new 'localhost', 8888
6 $db = Couch::Db.new $server, 'teddybear'
9 def lchomp(separator = $/)
10 reverse.chomp(separator).reverse
16 return nil if path.nil?
17 path.lchomp('/').split('/', 2)
21 class CouchDir < Couch::Doc
25 @subdirs = [] if @subdirs.nil?
29 _attachments.map { |a| a.name }
33 print "CONTENTS #{path}\n"
34 first, rest = peel_path path
38 find_subdir(first).contents rest
43 first, rest = peel_path path
47 find_subdir(first).file? rest
52 first, rest = peel_path path
53 return true if first.nil?
56 subdirs.include? first
58 find_subdir(first).directory? rest
63 print "executable? #{path}"
68 first, rest = peel_path path
70 f = _attachments.find { |a| a.name == first}
73 find_subdir(first).read_file rest
77 def write_to(path, data)
78 first, rest = peel_path path
80 # Stores the file as an attachment
87 find_subdir(first).write_to rest, data
92 first, rest = peel_path path
97 find_subdir(first).mkdir rest
102 print "RMDIR #{id}: #{path}\n"
103 first, rest = peel_path path
104 d = find_subdir(first)
115 subdir_id = id + '/' + dir
116 d = CouchDir.find_or_create @db, subdir_id
128 CouchDir.find_or_create @db, @name
131 def initialize(db, name)
138 print "contents #{path}\n"
139 root.contents path.lchomp('/') # num num num
141 print e.message + "\n"
142 print e.backtrace.join("\n") + "\n"
147 print "directory? #{path}\n"
148 root.directory? path.lchomp('/')
152 print "file? #{path}\n"
153 root.file? path.lchomp('/')
158 print "read_file #{path}\n"
159 root.read_file path.lchomp('/')
162 print err.backtrace.join("\n")
167 print "mkdir #{path}\n"
168 root.mkdir path.lchomp('/')
173 print "rmdir #{path}\n"
174 root.rmdir path.lchomp('/')
180 def write_to(path, data)
181 print "write_to #{path}, #{data.size} bytes\n"
182 root.write_to path.lchomp('/'), data
194 print "can_write? #{path}\n"
198 def can_delete?(path)
204 mount_point = ARGV.shift
206 root = Root.new $db, mount_point
209 FuseFS.mount_under mount_point