Class: McFS::Filesystem

Inherits:
Object
  • Object
show all
Defined in:
lib/mcfs/filesystem.rb

Instance Method Summary collapse

Constructor Details

#initializeFilesystem

Returns a new instance of Filesystem.



10
11
12
13
14
15
16
17
18
# File 'lib/mcfs/filesystem.rb', line 10

def initialize
  @stores = []
  dbcfg1 = YAML.load_file(ENV['HOME'] + '/.mcfs/dropbox1.yml')
  dbcfg2 = YAML.load_file(ENV['HOME'] + '/.mcfs/dropbox2.yml')
  
  @stores << Stores::Dropbox.new(dbcfg1.access_token)
  @stores << Stores::Dropbox.new(dbcfg2.access_token)
  
end

Instance Method Details

#can_write?(path) ⇒ Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/mcfs/filesystem.rb', line 32

def can_write?(path)
  true
end

#contents(path) ⇒ Object



20
21
22
23
24
25
26
# File 'lib/mcfs/filesystem.rb', line 20

def contents(path)
  files = []
  @stores.each do |store|
    files += store.contents(path)
  end
  files.uniq
end

#file?(path) ⇒ Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/mcfs/filesystem.rb', line 28

def file?(path)
  true
end

#read_file(path) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/mcfs/filesystem.rb', line 36

def read_file(path)
  puts "Read File: #{path}"
  contents = {}
  
  @stores.each do |store|
    contents.merge! store.read_file(path)
  end
  
  data = ''
  
  contents.sort.each do |chunk|
    data << chunk[1]
  end
  
  data
end

#write_to(path, str) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/mcfs/filesystem.rb', line 53

def write_to(path, str)
  puts "write_to: #{path}, #{str}"
  buf = ''
  cnt = 0
  idx = 0
  
  str.each_byte do |b|
    buf << b
    cnt += 1
    
    if cnt == 4096 then
      @stores[idx % @stores.size].write_to(path, idx, buf)
      buf = ''
      idx += 1
      cnt = 0
    end
  end
  
  if buf.size > 0 then
    puts buf.size
    puts idx
    p @stores
    puts @stores[idx % (@stores.size)]
    @stores[idx % @stores.size].write_to(path, idx, buf)
  end
  
end