Class: DokanFS::MetaDir

Inherits:
DokanDir show all
Defined in:
ext/dokan-ruby-0.1.5.1229/lib/dokanfs.rb

Instance Method Summary collapse

Methods inherited from DokanDir

#scan_path, #split_path

Constructor Details

#initializeMetaDir

Returns a new instance of MetaDir.



201
202
203
204
# File 'ext/dokan-ruby-0.1.5.1229/lib/dokanfs.rb', line 201

def initialize
  @subdirs  = Hash.new(nil)
  @files    = Hash.new(nil)
end

Instance Method Details

#can_delete?(path) ⇒ Boolean

Delete a file

Returns:

  • (Boolean)


294
295
296
297
298
299
300
301
302
303
304
305
306
307
# File 'ext/dokan-ruby-0.1.5.1229/lib/dokanfs.rb', line 294

def can_delete?(path)
  #return false unless Process.uid == FuseFS.reader_uid
  base, rest = split_path(path)
  case
  when base.nil?
    false
  when rest.nil?
    @files.has_key?(base)
  when ! @subdirs.has_key?(base)
    false
  else
    @subdirs[base].can_delete?(rest)
  end
end

#can_mkdir?(path) ⇒ Boolean

Make a new directory

Returns:

  • (Boolean)


324
325
326
327
328
329
330
331
332
333
334
335
336
337
# File 'ext/dokan-ruby-0.1.5.1229/lib/dokanfs.rb', line 324

def can_mkdir?(path)
  #return false unless Process.uid == FuseFS.reader_uid
  base, rest = split_path(path)
  case
  when base.nil?
    false
  when rest.nil?
    ! (@subdirs.has_key?(base) || @files.has_key?(base))
  when ! @subdirs.has_key?(base)
    false
  else
    @subdirs[base].can_mkdir?(rest)
  end
end

#can_rmdir?(path) ⇒ Boolean

Delete an existing directory.

Returns:

  • (Boolean)


355
356
357
358
359
360
361
362
363
364
365
366
367
368
# File 'ext/dokan-ruby-0.1.5.1229/lib/dokanfs.rb', line 355

def can_rmdir?(path)
  #return false unless Process.uid == FuseFS.reader_uid
  base, rest = split_path(path)
  case
  when base.nil?
    false
  when rest.nil?
    @subdirs.has_key?(base)
  when ! @subdirs.has_key?(base)
    false
  else
    @subdirs[base].can_rmdir?(rest)
  end
end

#can_write?(path) ⇒ Boolean

Write to a file

Returns:

  • (Boolean)


265
266
267
268
269
270
271
272
273
274
275
276
277
278
# File 'ext/dokan-ruby-0.1.5.1229/lib/dokanfs.rb', line 265

def can_write?(path)
  #return false unless Process.uid == FuseFS.reader_uid
  base, rest = split_path(path)
  case
  when base.nil?
    true
  when rest.nil?
    true
  when ! @subdirs.has_key?(base)
    false
  else
    @subdirs[base].can_write?(rest)
  end
end

#contents(path) ⇒ Object

Contents of directory.



207
208
209
210
211
212
213
214
215
216
217
218
219
# File 'ext/dokan-ruby-0.1.5.1229/lib/dokanfs.rb', line 207

def contents(path)
  base, rest = split_path(path)
  case
  when base.nil?
    (@files.keys + @subdirs.keys).sort.uniq
  when ! @subdirs.has_key?(base)
    nil
  when rest.nil?
    @subdirs[base].contents('/')
  else
    @subdirs[base].contents(rest)
  end
end

#delete(path) ⇒ Object



308
309
310
311
312
313
314
315
316
317
318
319
320
321
# File 'ext/dokan-ruby-0.1.5.1229/lib/dokanfs.rb', line 308

def delete(path)
  base, rest = split_path(path)
  case
  when base.nil?
    nil
  when rest.nil?
    # Delete it.
    @files.delete(base)
  when ! @subdirs.has_key?(base)
    nil
  else
    @subdirs[base].delete(rest)
  end
end

#directory?(path) ⇒ Boolean

File types

Returns:

  • (Boolean)


222
223
224
225
226
227
228
229
230
231
232
233
234
# File 'ext/dokan-ruby-0.1.5.1229/lib/dokanfs.rb', line 222

def directory?(path)
  base, rest = split_path(path)
  case
  when base.nil?
    true
  when ! @subdirs.has_key?(base)
    false
  when rest.nil?
    true
  else
    @subdirs[base].directory?(rest)
  end
end

#file?(path) ⇒ Boolean

Returns:

  • (Boolean)


235
236
237
238
239
240
241
242
243
244
245
246
247
# File 'ext/dokan-ruby-0.1.5.1229/lib/dokanfs.rb', line 235

def file?(path)
  base, rest = split_path(path)
  case
  when base.nil?
    false
  when rest.nil?
    @files.has_key?(base)
  when ! @subdirs.has_key?(base)
    false
  else
    @subdirs[base].file?(rest)
  end
end

#mkdir(path, dir = nil) ⇒ Object



338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
# File 'ext/dokan-ruby-0.1.5.1229/lib/dokanfs.rb', line 338

def mkdir(path,dir=nil)
  base, rest = split_path(path)
  case
  when base.nil?
    false
  when rest.nil?
    dir ||= MetaDir.new
    @subdirs[base] = dir
    true
  when ! @subdirs.has_key?(base)
    false
  else
    @subdirs[base].mkdir(rest,dir)
  end
end

#read_file(path) ⇒ Object

File Reading



250
251
252
253
254
255
256
257
258
259
260
261
262
# File 'ext/dokan-ruby-0.1.5.1229/lib/dokanfs.rb', line 250

def read_file(path)
  base, rest = split_path(path)
  case
  when base.nil?
    nil
  when rest.nil?
    @files[base].to_s
  when ! @subdirs.has_key?(base)
    nil
  else
    @subdirs[base].read_file(rest)
  end
end

#rmdir(path) ⇒ Object



369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
# File 'ext/dokan-ruby-0.1.5.1229/lib/dokanfs.rb', line 369

def rmdir(path)
  base, rest = split_path(path)
  dir ||= MetaDir.new
  case
  when base.nil?
    false
  when rest.nil?
    @subdirs.delete(base)
    true
  when ! @subdirs.has_key?(base)
    false
  else
    @subdirs[base].rmdir(rest,dir)
  end
end

#write_to(path, file) ⇒ Object



279
280
281
282
283
284
285
286
287
288
289
290
291
# File 'ext/dokan-ruby-0.1.5.1229/lib/dokanfs.rb', line 279

def write_to(path,file)
  base, rest = split_path(path)
  case
  when base.nil?
    false
  when rest.nil?
    @files[base] = file
  when ! @subdirs.has_key?(base)
    false
  else
    @subdirs[base].write_to(rest,file)
  end
end