Class: MTP::FileSystem
- Inherits:
-
FuseFS::FuseDir
- Object
- FuseFS::FuseDir
- MTP::FileSystem
show all
- Defined in:
- lib/mtp/fuse.rb
Defined Under Namespace
Classes: Albums, Artists, Genres, Playlists
Constant Summary
collapse
- @@logger =
Logger.new(STDERR)
- @@roots =
{}
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(device) ⇒ FileSystem
Returns a new instance of FileSystem.
25
26
27
28
|
# File 'lib/mtp/fuse.rb', line 25
def initialize(device)
@device = device
@device.objects
end
|
Class Method Details
12
13
14
|
# File 'lib/mtp/fuse.rb', line 12
def self.logger
@@logger
end
|
.register_root(name, klass) ⇒ Object
21
22
23
|
# File 'lib/mtp/fuse.rb', line 21
def self.register_root(name, klass)
@@roots[name] = klass
end
|
Instance Method Details
#can_delete?(path) ⇒ Boolean
107
108
109
110
111
|
# File 'lib/mtp/fuse.rb', line 107
def can_delete?(path)
dispatch(:can_delete?, path) do |path|
true
end
end
|
#can_mkdir?(path) ⇒ Boolean
119
120
121
122
123
|
# File 'lib/mtp/fuse.rb', line 119
def can_mkdir?(path)
dispatch(:can_mkdir?, path) do |path|
false
end
end
|
#can_rmdir?(path) ⇒ Boolean
131
132
133
134
135
|
# File 'lib/mtp/fuse.rb', line 131
def can_rmdir?(path)
dispatch(:can_rmdir?, path) do |path|
false
end
end
|
#can_write?(path) ⇒ Boolean
87
88
89
90
91
|
# File 'lib/mtp/fuse.rb', line 87
def can_write?(path)
dispatch(:can_write?, path) do |path|
@device[path.last].nil?
end
end
|
#contents(path) ⇒ Object
73
74
75
76
77
78
|
# File 'lib/mtp/fuse.rb', line 73
def contents(path)
logger.debug("#{path}: contents")
dispatch(:contents, path) do |path|
@@roots.keys
end
end
|
#delete(path) ⇒ Object
113
114
115
116
117
|
# File 'lib/mtp/fuse.rb', line 113
def delete(path)
dispatch(:delete, path) do |path|
@device.delete(@device[path.last])
end
end
|
#directory?(path) ⇒ Boolean
47
48
49
50
51
52
|
# File 'lib/mtp/fuse.rb', line 47
def directory?(path)
logger.debug("#{path}: directory?")
dispatch(:directory?, path) do |path|
@@roots.keys.include?(path)
end
end
|
#dispatch(method, *args, &block) ⇒ Object
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
# File 'lib/mtp/fuse.rb', line 30
def dispatch(method, *args, &block)
ps = scan_path(args.shift)
if ps.empty?
yield ps, *args
else
type = ps.shift
klass = @@roots[type]
handler = (klass.nil? ? nil : klass.new(@device))
if !handler.nil? and handler.respond_to?(method)
handler.send(method, ps, *args)
else
yield ps.unshift(type), *args
end
end
end
|
#executable?(path) ⇒ Boolean
61
62
63
64
|
# File 'lib/mtp/fuse.rb', line 61
def executable?(path)
logger.debug("#{path}: executable?")
false
end
|
#file?(path) ⇒ Boolean
54
55
56
57
58
59
|
# File 'lib/mtp/fuse.rb', line 54
def file?(path)
logger.debug("#{path}: file?")
dispatch(:file?, path) do |path|
false
end
end
|
16
17
18
|
# File 'lib/mtp/fuse.rb', line 16
def logger
@@logger
end
|
#mkdir(path) ⇒ Object
125
126
127
128
129
|
# File 'lib/mtp/fuse.rb', line 125
def mkdir(path)
dispatch(:mkdir, path) do |path|
false
end
end
|
#read_file(path) ⇒ Object
80
81
82
83
84
85
|
# File 'lib/mtp/fuse.rb', line 80
def read_file(path)
dispatch(:read_file, path) do |path|
track = @device[path.last]
@device.get(track)
end
end
|
#rmdir(path) ⇒ Object
137
138
139
140
|
# File 'lib/mtp/fuse.rb', line 137
def rmdir(path)
dispatch(:rmdir, path) do |path|
end
end
|
#size(path) ⇒ Object
66
67
68
69
70
71
|
# File 'lib/mtp/fuse.rb', line 66
def size(path)
logger.debug("#{path}: size")
dispatch(:size, path) do |path|
0
end
end
|
#write_to(path, str) ⇒ Object
93
94
95
96
97
98
99
100
101
102
103
104
105
|
# File 'lib/mtp/fuse.rb', line 93
def write_to(path, str)
dispatch(:write_to, path, str) do |path, str|
track = MTP::MP3Track.new
track.filename = path.last
track.compressed_size = str.length
track.data = MTP::Data.new(str)
@device.send(track)
StringIO.open(str, 'r') do |io|
info = Mp3Info.new(io)
track.set_properties_from_mp3info(info)
end
end
end
|