def open(self, path, flags, attr): print 'OPENING' permissions = self._get_bioshare_path_permissions(path) IS_WRITE = flags & os.O_CREAT or flags & os.O_WRONLY or flags & os.O_RDWR or flags & os.O_APPEND if not ((not IS_WRITE and Share.PERMISSION_VIEW in permissions and Share.PERMISSION_DOWNLOAD in permissions) or (IS_WRITE and Share.PERMISSION_WRITE in permissions and Share.PERMISSION_VIEW in permissions)): # if Share.PERMISSION_WRITE not in permissions: raise PermissionDenied() if flags & os.O_CREAT or flags & os.O_WRONLY or flags & os.O_RDWR or flags & os.O_APPEND: self._path_modified(path) path = self._realpath(path) try: binary_flag = getattr(os, 'O_BINARY', 0) flags |= binary_flag mode = getattr(attr, 'st_mode', None) if mode is not None: fd = os.open(path, flags, mode) else: # os.open() defaults to 0777 which is # an odd default mode for files fd = os.open(path, flags, o666) except OSError as e: return SFTPServer.convert_errno(e.errno) try: if (flags & os.O_CREAT) and (attr is not None): attr._flags &= ~attr.FLAG_PERMISSIONS SFTPServer.set_file_attr(path, attr) if flags & os.O_WRONLY: if flags & os.O_APPEND: fstr = 'ab' else: fstr = 'wb' elif flags & os.O_RDWR: if flags & os.O_APPEND: fstr = 'a+b' else: fstr = 'r+b' else: # O_RDONLY (== 0) fstr = 'rb' except Exception as e: print e.message try: f = os.fdopen(fd, fstr) except OSError as e: return SFTPServer.convert_errno(e.errno) fobj = SFTPHandle(flags,permissions=permissions) fobj.filename = path fobj.readfile = f fobj.writefile = f return fobj
'res_model': object2._name, 'partner_id': partner, 'res_id': object2.id }) cid = fobj.create(cr, uid, val, context={}) cr.commit() cr.close() f = file_wrapper('', cid, cr.dbname, uid, ) except Exception,e: log(e) raise OSError(1, 'Operation not permited.') if f : fobj = SFTPHandle(flags) fobj.filename = objname fobj.readfile = None fobj.writefile = f return fobj return False def remove(self, node): """ Remove """ assert node if node.type == 'collection': return self.rmdir(node) elif node.type == 'file': return self.rmfile(node) raise OSError(1, 'Operation not permited.') def rmfile(self, node):
cr.commit() cr.close() f = file_wrapper( '', cid, cr.dbname, uid, ) except Exception, e: log(e) raise OSError(1, 'Operation not permited.') if f: fobj = SFTPHandle(flags) fobj.filename = objname fobj.readfile = None fobj.writefile = f return fobj return False def remove(self, node): """ Remove """ assert node if node.type == 'collection': return self.rmdir(node) elif node.type == 'file': return self.rmfile(node) raise OSError(1, 'Operation not permited.') def rmfile(self, node):