-
Notifications
You must be signed in to change notification settings - Fork 1
/
hardlink.py
66 lines (54 loc) · 2.1 KB
/
hardlink.py
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
from root import Root
from log import log
from operations import Operations, Op1, Op2
from util.attr import issubclass
from posix import stat_result
from stat import S_IFLNK
import os
class Hardlink( Root):
getattr4symlink = False
def _dispatch( me):
path = os.path.sep + me.q.path_in_aspect
return me.context.get_op( me.q.op_klas)( path, *me.args)
def _external_dispatch( me, ext):
path2 = os.path.sep + me.q2.path_in_aspect
op_klas = me.q2.op_klas
if issubclass( op_klas, Operations.symlink):
Hardlink.getattr4symlink = True
op_klas = Operations.link
return me.context.get_op( op_klas)( ext.path, path2)
class Parser( Root.Parser):
def _parse( me):
return 'dispatch'
def check4alias( me):
return None
class readdir( Root.readdir):
def _get_aspect_dirs(me):
return [ name for name in Root.readdir._get_aspect_dirs(me) if name != Hardlink.dir_name() ]
class getattr_( Root.getattr):
_dispatch = Hardlink._dispatch.im_func
def dispatch( me):
stat_res = me._dispatch()
#if os.path.split( me.q.path_in_aspect)[0] and isinstance( stat_res, stat_result):
if Hardlink.getattr4symlink and isinstance( stat_res, stat_result):
all = list(stat_res)
log('original:', all)
all[0] = all[0] | S_IFLNK
log('new:', all)
stat_res = stat_result( all)
Hardlink.getattr4symlink = False
return stat_res
Hardlink.getattr = getattr_
for op_name, op_klas in vars(Operations).iteritems():
if not issubclass( op_klas, (Op1, Op2)): continue
klas = getattr( Hardlink, op_name, op_klas)
A = None
if issubclass( op_klas, Op1) and not getattr( klas, 'dispatch', None):
class A( klas):
dispatch = Hardlink._dispatch.im_func
if issubclass( op_klas, Op2) and not getattr( klas, 'external_dispatch', None):
class A( klas):
external_dispatch = Hardlink._external_dispatch.im_func
if A:
setattr( Hardlink, op_name, A)
# vim:ts=4:sw=4:expandtab