-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathffs.coffee
75 lines (54 loc) · 1.47 KB
/
ffs.coffee
1
2
3
4
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
Path = require('path')
f4js = require('fuse4js')
_ = require('underscore')
{Flickr} = require('flickr-with-uploads')
FlickrStore = require('./store.coffee')
process.env.DEBUG ?= '*'
debug = require('debug')('FFS:FS')
ERRORS =
ENOENT: 2 # Not found
EIO: 5 # IO Error
EINVAL: 22 # Not a directory
class FlickrFS
constructor: (@store, @opts={}) ->
init: (cb) =>
debug("init")
do cb
getattr: (path, cb) =>
debug("getattr", path)
code = 0
stat = {}
@store.info path, (err, info) ->
if err?
code = -ERRORS.EIO
else if not info
code = -ERRORS.ENOENT
else if info.type is 'directory'
# A directory
stat =
size: 4096,
mode: 0o40777
else
# A file
stat =
size: info.size,
mode: +"0o100#{ info.mode }"
cb(code, stat)
readdir: (path, cb) =>
debug("readdir", path)
list = null
code = 0
@store.list path, (err, files) ->
if err?
code = -ERRORS[err.code ? 'EIO']
else
list = _.map(files, (info) -> Path.basename(info.path))
cb(code, list)
start = (opts) ->
client = new Flickr(opts.API_KEY, opts.API_SECRET, opts.ACCESS_TOKEN, opts.ACCESS_SECRET)
store = new FlickrStore(client, opts)
handlers = new FlickrFS(store, opts)
opts.mount = '/Users/zackbloom/mounts/14'
f4js.start opts.mount, handlers, true
debug "Started at #{ opts.mount }"
module.exports = {FlickrFS, start}