示例#1
0
 def on_post(self, req, resp, cn):
     namespace = ("user.%s." % self.namespace).encode("ascii")
     try:
         path, buf, cert, signed, expires = self.authority.get_signed(cn)
     except IOError:
         raise falcon.HTTPNotFound()
     else:
         for key in req.params:
             if not re.match("[a-z0-9_\.]+$", key):
                 raise falcon.HTTPBadRequest("Invalid key %s" % key)
         valid = set()
         modified = False
         for key, value in req.params.items():
             identifier = ("user.%s.%s" %
                           (self.namespace, key)).encode("ascii")
             try:
                 if getxattr(path, identifier).decode("utf-8") != value:
                     modified = True
             except OSError:  # no such attribute
                 pass
             setxattr(path, identifier, value.encode("utf-8"))
             valid.add(identifier)
         for key in listxattr(path):
             if not key.startswith(namespace):
                 continue
             if key not in valid:
                 modified = True
                 removexattr(path, key)
         if modified:
             push.publish("attribute-update", cn)
示例#2
0
def main():
    banner()
    p = raw_input(
        "Please provide the BAD back-end file system folder NOT the mountpoint: "
    )
    while not os.path.isdir(p):
        p = raw_input(
            "Invalid input %s is not a directory, please enter the correct path: "
            % p)
    a = raw_input(
        "Last chance to back out, are you sure you want me to walk %s and remove all gluster xattrs I find? (y/n): "
        % p)
    while a.lower() not in ('y', 'n'):
        a = raw_input("Invalid input %s, please specify y or n: " % a)
    if a.lower() == 'n':
        sys.exit(0)
    '''
        Now we have a valid path, and user concent
    '''

    for root, dirs, files in os.walk(p):
        '''
            At the time of writing gluster only sets xarrts on directories
        '''
        xattrs = xattr.listxattr(root)
        if len(xattrs) > 0:
            if 'trusted.gfid' in xattrs:
                print("Found trusted.gfid set on %s" % root)
                xattr.removexattr(root, 'trusted.gfid')
            for attr in xattrs:
                if reAFR.search(attr):
                    print("Found truster.afr.* set on %s" % root)
                    xattr.removexattr(root, attr)
示例#3
0
def main():
    banner()
    p = raw_input("Please provide the BAD back-end file system folder NOT the mountpoint: ")
    while not os.path.isdir(p):
       p = raw_input("Invalid input %s is not a directory, please enter the correct path: "%p)
    a = raw_input("Last chance to back out, are you sure you want me to walk %s and remove all gluster xattrs I find? (y/n): "%p)
    while a.lower() not in ('y','n'):
        a = raw_input("Invalid input %s, please specify y or n: "%a)
    if a.lower() == 'n':
        sys.exit(0)
    '''
        Now we have a valid path, and user concent
    '''
    
    for root, dirs, files in os.walk(p):
        '''
            At the time of writing gluster only sets xarrts on directories
        '''
        xattrs = xattr.listxattr(root)
        if len(xattrs) > 0:
            if 'trusted.gfid' in xattrs:
                print("Found trusted.gfid set on %s"%root)
                xattr.removexattr(root,'trusted.gfid')
            for attr in xattrs:
                if reAFR.search(attr):
                    print("Found truster.afr.* set on %s"%root)
                    xattr.removexattr(root,attr)
示例#4
0
 def is_partition_supported(self, folder):
     if folder is None:
         return False
     result = False
     to_delete = not os.path.exists(folder)
     try:
         if to_delete:
             os.mkdir(folder)
         if not os.access(folder, os.W_OK):
             import stat
             os.chmod(
                 folder, stat.S_IXUSR | stat.S_IRGRP | stat.S_IXGRP
                 | stat.S_IRUSR | stat.S_IWGRP | stat.S_IWUSR)
         import xattr
         attr = "drive-test"
         xattr.setxattr(folder, attr, attr)
         if xattr.getxattr(folder, attr) == attr:
             result = True
         xattr.removexattr(folder, attr)
     finally:
         try:
             if to_delete:
                 os.rmdir(folder)
         except:
             pass
     return result
示例#5
0
def _removexattr(file, key):
    try:
        xattr.removexattr(file, key)
    except Exception as err:
        return False, err

    return True, ''
示例#6
0
 def _checkDeprecated(self, item, symlink=False):
     """check deprecated list, set, get operations against an item"""
     self.checkList(xattr.listxattr(item, symlink), [])
     self.assertRaises(EnvironmentError, xattr.setxattr, item,
                       self.USER_ATTR, self.USER_VAL, XATTR_REPLACE)
     try:
         xattr.setxattr(item, self.USER_ATTR, self.USER_VAL, 0, symlink)
     except IOError:
         err = sys.exc_info()[1]
         if symlink and (err.errno == errno.EPERM
                         or err.errno == errno.ENOENT):
             # symlinks may fail, in which case we abort the rest
             # of the test for this case (Linux returns EPERM; OS X returns ENOENT)
             return
         raise
     self.assertRaises(EnvironmentError, xattr.setxattr, item,
                       self.USER_ATTR, self.USER_VAL, XATTR_CREATE)
     self.checkList(xattr.listxattr(item, symlink), [self.USER_ATTR])
     self.assertEqual(xattr.getxattr(item, self.USER_ATTR, symlink),
                      self.USER_VAL)
     self.checkTuples(xattr.get_all(item, nofollow=symlink),
                      [(self.USER_ATTR, self.USER_VAL)])
     xattr.removexattr(item, self.USER_ATTR)
     self.checkList(xattr.listxattr(item, symlink), [])
     self.checkTuples(xattr.get_all(item, nofollow=symlink), [])
     self.assertRaises(EnvironmentError, xattr.removexattr, item,
                       self.USER_ATTR)
示例#7
0
 def is_partition_supported(self, folder):
     if folder is None:
         return False
     result = False
     to_delete = not os.path.exists(folder)
     try:
         if to_delete:
             os.mkdir(folder)
         if not os.access(folder, os.W_OK):
             import stat
             os.chmod(folder, stat.S_IXUSR | stat.S_IRGRP | stat.S_IXGRP |
                             stat.S_IRUSR | stat.S_IWGRP | stat.S_IWUSR)
         import xattr
         attr = "drive-test"
         xattr.setxattr(folder, attr, attr)
         if xattr.getxattr(folder, attr) == attr:
             result = True
         xattr.removexattr(folder, attr)
     finally:
         try:
             if to_delete:
                 os.rmdir(folder)
         except:
             pass
     return result
示例#8
0
 def is_partition_supported(folder: str) -> bool:
     if folder is None:
         return False
     result = False
     to_delete = not os.path.exists(folder)
     try:
         if to_delete:
             os.mkdir(folder)
         if not os.access(folder, os.W_OK):
             os.chmod(
                 folder,
                 stat.S_IXUSR
                 | stat.S_IRGRP
                 | stat.S_IXGRP
                 | stat.S_IRUSR
                 | stat.S_IWGRP
                 | stat.S_IWUSR,
             )
         key, value = "drive-test", b"drive-test"
         xattr.setxattr(folder, key, value)
         if xattr.getxattr(folder, key) == value:
             result = True
         xattr.removexattr(folder, key)
     finally:
         if to_delete:
             try:
                 os.rmdir(folder)
             except:
                 pass
     return result
示例#9
0
 def remove_remote_id(self, ref, name='ndrive'):
     # Can be move to another class
     path = self._abspath(ref)
     log.trace('Removing xattr %s from %s', name, path)
     locker = self.unlock_path(path, False)
     if AbstractOSIntegration.is_windows():
         pathAlt = path + ":" + name
         try:
             os.remove(pathAlt)
         except WindowsError as e:
             if e.errno == os.errno.EACCES:
                 self.unset_path_readonly(path)
                 os.remove(pathAlt)
                 self.set_path_readonly(path)
             else:
                 raise e
         finally:
             self.lock_path(path, locker)
     else:
         try:
             import xattr
             if AbstractOSIntegration.is_mac():
                 xattr.removexattr(path, name)
             else:
                 xattr.removexattr(path, 'user.' + name)
         finally:
             self.lock_path(path, locker)
示例#10
0
 def remove_remote_id(self, ref, name='ndrive'):
     # Can be move to another class
     path = self._abspath(ref)
     log.trace('Removing xattr %s from %s', name, path)
     locker = self.unlock_path(path, False)
     if AbstractOSIntegration.is_windows():
         pathAlt = path + ":" + name
         try:
             if os.path.exists(pathAlt):
                 os.remove(pathAlt)
         except WindowsError as e:
             if e.errno == os.errno.EACCES:
                 self.unset_path_readonly(path)
                 os.remove(pathAlt)
                 self.set_path_readonly(path)
             else:
                 raise e
         finally:
             self.lock_path(path, locker)
     else:
         try:
             import xattr
             if AbstractOSIntegration.is_mac():
                 xattr.removexattr(path, name)
             else:
                 xattr.removexattr(path, 'user.' + name)
         except IOError as e:
             # Ignore IOError: [Errno 93] Attribute not found ( Mac )
             # IOError: [Errno 61] No data available ( Linux )
             if e.errno == 93 or e.errno == 61:
                 pass
             else:
                 raise
         finally:
             self.lock_path(path, locker)
示例#11
0
def test_mixed_access(testdir, gen):
    """test mixed access to file"""
    with gen(testdir) as (a, b):
        # Check empty
        lists_equal(xattr.list(a), [])
        lists_equal(xattr.listxattr(b), [])

        # Check value
        xattr.set(a, USER_ATTR, USER_VAL)
        for i in [a, b]:
            # Deprecated functions
            lists_equal(xattr.listxattr(i), [USER_ATTR])
            assert xattr.getxattr(i, USER_ATTR) == USER_VAL
            tuples_equal(xattr.get_all(i), [(USER_ATTR, USER_VAL)])
            # Current functions
            lists_equal(xattr.list(i), [USER_ATTR])
            assert xattr.list(i, namespace=NAMESPACE) == [USER_NN]
            assert xattr.get(i, USER_ATTR) == USER_VAL
            assert xattr.get(i, USER_NN, namespace=NAMESPACE) == USER_VAL
            tuples_equal(xattr.get_all(i),
                         [(USER_ATTR, USER_VAL)])
            assert xattr.get_all(i, namespace=NAMESPACE) == \
                [(USER_NN, USER_VAL)]

        # Overwrite
        xattr.set(b, USER_ATTR, LARGE_VAL, flags=xattr.XATTR_REPLACE)
        assert xattr.get(a, USER_ATTR) == LARGE_VAL
        assert xattr.getxattr(a, USER_ATTR) == LARGE_VAL
        xattr.removexattr(b, USER_ATTR)
        assert xattr.get_all(a, namespace=NAMESPACE) == []
        assert xattr.get_all(b, namespace=NAMESPACE) == []
示例#12
0
 def remove_remote_id(self, ref, name='ndrive'):
     # Can be move to another class
     path = self._abspath(ref)
     log.trace('Removing xattr %s from %s', name, path)
     locker = self.unlock_path(path, False)
     if AbstractOSIntegration.is_windows():
         pathAlt = path + ":" + name
         try:
             if os.path.exists(pathAlt):
                 os.remove(pathAlt)
         except WindowsError as e:
             if e.errno == os.errno.EACCES:
                 self.unset_path_readonly(path)
                 os.remove(pathAlt)
                 self.set_path_readonly(path)
             else:
                 raise e
         finally:
             self.lock_path(path, locker)
     else:
         try:
             import xattr
             if AbstractOSIntegration.is_mac():
                 xattr.removexattr(path, name)
             else:
                 xattr.removexattr(path, 'user.' + name)
         except IOError as e:
             # Ignore IOError: [Errno 93] Attribute not found ( Mac )
             # IOError: [Errno 61] No data available ( Linux )
             if e.errno == 93 or e.errno == 61:
                 pass
             else:
                 raise
         finally:
             self.lock_path(path, locker)
示例#13
0
 def is_partition_supported(folder: Path) -> bool:
     if folder is None:
         return False
     result = False
     to_delete = not folder.exists()
     try:
         if to_delete:
             folder.mkdir()
         if not os.access(folder, os.W_OK):
             folder.chmod(stat.S_IXUSR
                          | stat.S_IRGRP
                          | stat.S_IXGRP
                          | stat.S_IRUSR
                          | stat.S_IWGRP
                          | stat.S_IWUSR)
         key, value = "drive-test", b"drive-test"
         xattr.setxattr(folder, key, value)
         if xattr.getxattr(folder, key) == value:
             result = True
         xattr.removexattr(folder, key)
     finally:
         if to_delete:
             with suppress(OSError):
                 folder.rmdir()
     return result
示例#14
0
 def _checkDeprecated(self, item, symlink=False):
     """check deprecated list, set, get operations against an item"""
     self.assertEqual(self._ignore(xattr.listxattr(item, symlink)),
                      [])
     self.assertRaises(EnvironmentError, xattr.setxattr, item,
                       self.USER_ATTR, self.USER_VAL,
                       XATTR_REPLACE)
     try:
         xattr.setxattr(item, self.USER_ATTR, self.USER_VAL, 0, symlink)
     except IOError:
         err = sys.exc_info()[1]
         if err.errno == errno.EPERM and symlink:
             # symlinks may fail, in which case we abort the rest
             # of the test for this case
             return
         raise
     self.assertRaises(EnvironmentError, xattr.setxattr, item,
                       self.USER_ATTR, self.USER_VAL, XATTR_CREATE)
     self.assertEqual(self._ignore(xattr.listxattr(item, symlink)),
                      [self.USER_ATTR])
     self.assertEqual(xattr.getxattr(item, self.USER_ATTR, symlink),
                      self.USER_VAL)
     self.assertEqual(self._ignore_tuples(xattr.get_all(item,
                                                        nofollow=symlink)),
                      [(self.USER_ATTR, self.USER_VAL)])
     xattr.removexattr(item, self.USER_ATTR)
     self.assertEqual(self._ignore(xattr.listxattr(item, symlink)),
                      [])
     self.assertEqual(self._ignore_tuples(xattr.get_all(item,
                                                        nofollow=symlink)),
                      [])
     self.assertRaises(EnvironmentError, xattr.removexattr,
                       item, self.USER_ATTR)
示例#15
0
def check_user_xattr(path):
    if not os.path.exists(path):
        return False
    do_setxattr(path, 'user.test.key1', 'value1')
    try:
        removexattr(path, 'user.test.key1')
    except Exception, err:
        logging.exception("removexattr failed on %s err: %s", path, str(err))
示例#16
0
def check_user_xattr(path):
    if not os.path.exists(path):
        return False
    do_setxattr(path, 'user.test.key1', 'value1')
    try:
        removexattr(path, 'user.test.key1')
    except Exception, err:
        logging.exception("removexattr failed on %s err: %s", path, str(err))
示例#17
0
def remove_the_meta(file_name):
    """Example of removing the keys added to the file."""
    xattr.removexattr(file_name, 'custom.comment')
    xattr.removexattr(file_name, 'Music.Artist')
    attrz = xattr.listxattr(file_name)
    result = ("C. Info Removed Meta: {}".format(attrz))
    print("{}".format(result))
    return result
示例#18
0
 def delete(self, name):
     try:
         xattr.removexattr(self._path, name)
     except IOError as e:
         if e.errno == errno.ENODATA or e.errno == errno.EOPNOTSUPP or e.errno == errno.ENOENT:
             raise KeyError(name)
         else:
             raise
示例#19
0
 def remove_the_meta(self):
     """Example of removing the keys added to the file."""
     print("Delete The Meta.")
     xattr.removexattr(self.file_name, 'custom.comment')
     attrz = xattr.listxattr(self.file_name)
     result = ("D. Info Removed Meta: {}".format(attrz))
     print("{}".format(result))
     print("The Meta Has Been Removed.")
     return result
示例#20
0
文件: utils.py 项目: vbellur/UFO
def clean_metadata(path):
    key = 0
    while True:
        try:
            value = getxattr(path, '%s%s' % (METADATA_KEY, (key or '')))
        except IOError:
            break;
        removexattr(path, '%s%s' % (METADATA_KEY, (key or '')))
        key += 1
示例#21
0
def test_binary_payload_deprecated(subject):
    """test binary values (deprecated functions)"""
    item = subject[0]
    BINVAL = b"abc\0def"
    xattr.setxattr(item, USER_ATTR, BINVAL)
    lists_equal(xattr.listxattr(item), [USER_ATTR])
    assert xattr.getxattr(item, USER_ATTR) == BINVAL
    tuples_equal(xattr.get_all(item), [(USER_ATTR, BINVAL)])
    xattr.removexattr(item, USER_ATTR)
示例#22
0
 def remove_remote_id_impl(self, path: Path, name: str = "ndrive") -> None:
     """Remove a given extended attribute."""
     try:
         xattr.removexattr(str(path), name)
     except OSError as exc:
         # EPROTONOSUPPORT: protocol not supported (xattr)
         # ENODATA: no data available
         if exc.errno not in (errno.ENODATA, errno.EPROTONOSUPPORT):
             raise exc
示例#23
0
 def _remove_remote_id_unix(path: Path, name: str = "ndrive") -> None:
     if LINUX:
         name = f"user.{name}"
     try:
         xattr.removexattr(str(path), name)
     except OSError as exc:
         # EPROTONOSUPPORT: protocol not supported (xattr)
         # ENODATA: no data available
         if exc.errno not in {errno.ENODATA, errno.EPROTONOSUPPORT}:
             raise exc
示例#24
0
 def remove_all_the_meta(self):
     """Example of removing the keys added to the file."""
     print("Deleting All Meta.")
     attrz = xattr.listxattr(self.file_name)
     for i in reversed(attrz):
         xattr.removexattr(self.file_name, i)
         print("    {}: Removed".format(i))
     print("")
     print("All Meta Has Been Removed.")
     return
示例#25
0
def comment_set(path, comment=None):
    assert_exists(path)
    if comment is None:
        xattr.removexattr(path, kMDItemFinderComment)
        return
    old = comment_get(path)
    if comment != old:
        if comment is not None and hasattr(comment, "encode"):
            comment = comment.encode("utf-8")  # str/bytes required
        xattr.setxattr(path, kMDItemFinderComment, comment)
示例#26
0
def write(path, comment=None):
    """write Finder comment"""
    if comment is None:
        xattr.removexattr(path, kMDItemFinderComment)
        return
    old = read(path)
    if comment != old:
        if comment is not None and hasattr(comment, "encode"):
            comment = comment.encode("utf-8")  # str/bytes required
        xattr.setxattr(path, kMDItemFinderComment, comment)
示例#27
0
 def on_delete(self, req, resp, cn, tag):
     path, buf, cert = authority.get_signed(cn)
     tags = set(getxattr(path, "user.xdg.tags").split(","))
     tags.remove(tag)
     if not tags:
         removexattr(path, "user.xdg.tags")
     else:
         setxattr(path, "user.xdg.tags", ",".join(tags))
     logger.debug(u"Tag %s removed for %s" % (tag, cn))
     push.publish("tag-update", cn)
示例#28
0
    def remove(clazz, filename, key):
        'Remove the attirbute with key from filename.'
        filename = file_check.check_file(filename)
        key = clazz._check_key(key)
        clazz.check_file_is_writable(filename)

        clazz._log.log_method_d()

        encoded_key = clazz._encode_key(key)
        xattr.removexattr(filename, encoded_key)
示例#29
0
def clean_metadata(path):
    key = 0
    while True:
        try:
            xattr.removexattr(path, '%s%s' % (METADATA_KEY, (key or '')))
        except IOError as err:
            if err.errno == errno.ENODATA:
                break
            raise
        key += 1
示例#30
0
 def testSymlinkOpsDeprecated(self):
     """test symlink operations (deprecated functions)"""
     _, sname = self._getsymlink()
     self.assertRaises(EnvironmentError, xattr.listxattr, sname)
     self._checkDeprecated(sname, symlink=True)
     target, sname = self._getsymlink(dangling=False)
     xattr.setxattr(target, self.USER_ATTR, self.USER_VAL)
     self.assertEqual(xattr.listxattr(target), [self.USER_ATTR])
     self.assertEqual(xattr.listxattr(sname, True), [])
     self.assertRaises(EnvironmentError, xattr.removexattr, sname, self.USER_ATTR, True)
     xattr.removexattr(sname, self.USER_ATTR, False)
示例#31
0
def test_set_get_remove_deprecated(subject):
    """check deprecated list, set, get operations against an item"""
    item = subject[0]
    lists_equal(xattr.listxattr(item), [])
    xattr.setxattr(item, USER_ATTR, USER_VAL, 0)
    lists_equal(xattr.listxattr(item), [USER_ATTR])
    assert xattr.getxattr(item, USER_ATTR) == USER_VAL
    tuples_equal(xattr.get_all(item), [(USER_ATTR, USER_VAL)])
    xattr.removexattr(item, USER_ATTR)
    lists_equal(xattr.listxattr(item), [])
    tuples_equal(xattr.get_all(item), [])
示例#32
0
文件: tag.py 项目: werty1st/certidude
 def on_delete(self, req, resp, cn, tag):
     path, buf, cert, signed, expires = self.authority.get_signed(cn)
     tags = set(getxattr(path, "user.xdg.tags").decode("utf-8").split(","))
     tags.remove(tag)
     if not tags:
         removexattr(path, "user.xdg.tags")
     else:
         setxattr(path, "user.xdg.tags", ",".join(tags))
     logger.info("Tag %s removed for %s by %s" %
                 (tag, cn, req.context.get("user")))
     push.publish("tag-update", cn)
示例#33
0
def clean_metadata(path_or_fd):
    key = 0
    while True:
        try:
            xattr.removexattr(path_or_fd, '%s%s' % (METADATA_KEY, (key or '')))
        except IOError as err:
            if err.errno == errno.ENODATA:
                break
            raise GlusterFileSystemIOError(
                err.errno, 'xattr.removexattr("%s", %s)' % (path_or_fd, key))
        key += 1
示例#34
0
文件: imgen.py 项目: boonleng/s2f
def grab(args, timeout=10):
    browser = webdriver.Safari()
    browser.set_window_size(1200, 1200)
    browser.implicitly_wait(10)

    for url, destination in ((
            'https://www.blockchain.com/charts/total-bitcoins',
            'btc-total-bitcoins.csv'),
                             ('https://www.blockchain.com/charts/market-cap',
                              'btc-market-cap.csv')):
        if args.verbose:
            print('Visiting {}'.format(url))
        browser.get(url)
        WebDriverWait(browser, timeout).until(
            EC.visibility_of_element_located((By.CLASS_NAME, 'vx-group')))
        button = browser.find_element_by_xpath('//button[text()="All Time"]')
        if button is None:
            print('Unable to find the All Time button')
            return
        graph = browser.find_element_by_xpath(
            '//*[name()="path" and contains(@d, "M100")]')
        if graph is None:
            print('Unable to find the graph area')
            return
        old = graph.get_attribute('d')
        if args.verbose:
            print('Clicking the "All Time" button ...')
        button.click()
        k = 0
        for k in range(timeout * 10):
            new = graph.get_attribute('d')
            if new != old:
                break
            if k % 10 == 0:
                print('Waiting for graph data ...')
            time.sleep(0.1)
        if args.verbose:
            print('Graph updated')
        select = Select(
            WebDriverWait(browser, timeout).until(
                EC.element_to_be_clickable(
                    (By.XPATH, '//*[name()="select"]'))))
        if args.verbose:
            print('Selecting "CSV Format" ...')
        select.select_by_visible_text('CSV Format')
        filename = os.path.expanduser('~/Downloads/Unknown')
        while not os.path.exists(filename):
            time.sleep(0.1)
        print('File downloaded')
        for a in xattr.listxattr(filename):
            xattr.removexattr(filename, a)
        os.rename(filename, destination)

    browser.quit()
示例#35
0
    def test_index_chunk_missing_xattr(self):
        # create a fake chunk
        chunk_path, container_id, content_id, chunk_id = self._create_chunk(
            self.rawx_conf['path'])

        # remove mandatory xattr
        xattr.removexattr(chunk_path, 'user.grid.chunk.hash')

        # try to index the chunk
        indexer = BlobIndexer(self.conf)

        self.assertRaises(FaultyChunk, indexer.update_index, chunk_path)
示例#36
0
 def testBinaryPayloadDeprecated(self):
     """test binary values (deprecated functions)"""
     fh, fname = self._getfile()
     os.close(fh)
     BINVAL = "abc" + '\0' + "def"
     if PY3K:
         BINVAL = BINVAL.encode()
     xattr.setxattr(fname, self.USER_ATTR, BINVAL)
     self.checkList(xattr.listxattr(fname), [self.USER_ATTR])
     self.assertEqual(xattr.getxattr(fname, self.USER_ATTR), BINVAL)
     self.checkTuples(xattr.get_all(fname), [(self.USER_ATTR, BINVAL)])
     xattr.removexattr(fname, self.USER_ATTR)
示例#37
0
 def testSymlinkOpsDeprecated(self):
     """test symlink operations (deprecated functions)"""
     _, sname = self._getsymlink()
     self.assertRaises(EnvironmentError, xattr.listxattr, sname)
     self._checkDeprecated(sname, symlink=True)
     target, sname = self._getsymlink(dangling=False)
     xattr.setxattr(target, self.USER_ATTR, self.USER_VAL)
     self.checkList(xattr.listxattr(target), [self.USER_ATTR])
     self.checkList(xattr.listxattr(sname, True), [])
     self.assertRaises(EnvironmentError, xattr.removexattr, sname,
                       self.USER_ATTR, True)
     xattr.removexattr(sname, self.USER_ATTR, False)
示例#38
0
    def _remove_remote_id_unix(path, name='ndrive'):
        # type: (Text, Text) -> None

        if sys.platform == 'linux2':
            name = 'user.' + name
        try:
            xattr.removexattr(path, name)
        except IOError as exc:
            # EPROTONOSUPPORT: protocol not supported (xattr)
            # ENODATA: no data available
            if exc.errno not in (errno.ENODATA, errno.EPROTONOSUPPORT):
                raise exc
示例#39
0
 def testBinaryPayloadDeprecated(self):
     """test binary values (deprecated functions)"""
     fh, fname = self._getfile()
     os.close(fh)
     BINVAL = "abc" + "\0" + "def"
     if PY3K:
         BINVAL = BINVAL.encode()
     xattr.setxattr(fname, self.USER_ATTR, BINVAL)
     self.assertEqual(xattr.listxattr(fname), [self.USER_ATTR])
     self.assertEqual(xattr.getxattr(fname, self.USER_ATTR), BINVAL)
     self.assertEqual(xattr.get_all(fname), [(self.USER_ATTR, BINVAL)])
     xattr.removexattr(fname, self.USER_ATTR)
示例#40
0
def change_file(path, trusted):
    """Change the trust state of a file"""

    # Save the original permissions of the file
    orig_perms = os.stat(path).st_mode

    # See if the file is readable
    try:
        with open(path):
            pass

    except IOError:
        # Try to unlock file to get read access
        safe_chmod(path, 0o644, 'Could not unlock {} for reading'.format(path))
    if trusted:
        # Set file to trusted
        # AKA remove our xattr
        file_xattrs = xattr.get_all(path)
        untrusted_attribute = (b'user.qubes.untrusted', b'true')

        # Check if the xattr exists first
        if untrusted_attribute in file_xattrs:
            try:
                xattr.removexattr(path, 'user.qubes.untrusted')
            except:
                # Unable to remove our xattr, return original permissions
                error(
                    'Unable to remove untrusted attribute on {}'.format(path))
                safe_chmod(path, orig_perms,
                           'Unable to set original perms. on {}'.format(path))

        # Remove visual attributes
        set_visual_attributes(path, False)

    else:
        # Set file to untrusted
        # AKA add our xattr and lock
        try:
            xattr.setxattr(path, 'user.qubes.untrusted', 'true')
            safe_chmod(
                path, 0o0,
                'Unable to set untrusted permissions on: {}'.format(path))
        except:
            # Unable to remove our xattr, return original permissions
            safe_chmod(
                path, orig_perms,
                'Unable to return perms after setting as untrusted: {}'.format(
                    path))
            sys.exit(65)

        # Add visual attributes
        set_visual_attributes(path, True)
示例#41
0
    def test_index_chunk_missing_xattr(self):
        rawx_conf = self.conf["rawx"][0]

        # create a fake chunk
        chunk_path, container_id, content_id, chunk_id = self._create_chunk(rawx_conf["path"])

        # remove mandatory xattr
        xattr.removexattr(chunk_path, "user.grid.chunk.hash")

        # try to index the chunk
        indexer = BlobIndexerWorker(self.gridconf, None, rawx_conf["path"])

        self.assertRaises(FaultyChunk, indexer.update_index, chunk_path)
示例#42
0
def do_removexattr(path, key):
    fd = None
    if not os.path.isdir(path):
        fd = do_open(path, 'rb')
    else:
        fd = path
    if fd or os.path.isdir(path):
        try:
            removexattr(fd, key)
        except Exception, err:
            logging.exception("removexattr failed on %s key %s err: %s", path, key, str(err))
            raise
        finally:
示例#43
0
def xattr_del(xfile, xsetter):
    """
    Remove extended file attributes
    Accepts a list/array with attrib names that are not prefixed with the 'user.' namespace
    """
    for k in xsetter:
        try:
            xattr.removexattr(xfile, 'user.'+str(k))
        except Exception as e:
            logthis("Failed to remove extended file attributes for", suffix=xfile, loglevel=LL.WARNING)
            logthis("xattr:", suffix=e, loglevel=LL.WARNING)
            return False

    return True
示例#44
0
def do_removexattr(path, key):
    fd = None
    if not os.path.isdir(path):
        fd = do_open(path, 'rb')
    else:
        fd = path
    if fd or os.path.isdir(path):
        try:
            removexattr(fd, key)
        except Exception, err:
            logging.exception("removexattr failed on %s key %s err: %s", path,
                              key, str(err))
            raise
        finally:
示例#45
0
文件: utils.py 项目: vbellur/UFO
def check_user_xattr(path):
    if not os.path.exists(path):
        return False
    try:
        setxattr(path, 'user.key1', 'value1')
    except:
        raise
        return False
    try:
        removexattr(path, 'user.key1')
    except:
        raise
        return False
    return True
示例#46
0
def check_user_xattr(path):
    if not os_path.exists(path):
        return False
    try:
        xattr.setxattr(path, 'user.test.key1', 'value1')
    except IOError as err:
        logging.exception("check_user_xattr: set failed on %s err: %s", path, str(err))
        raise
    try:
        xattr.removexattr(path, 'user.test.key1')
    except IOError as err:
        logging.exception("check_user_xattr: remove failed on %s err: %s", path, str(err))
        #Remove xattr may fail in case of concurrent remove.
    return True
示例#47
0
def main():
    if len(sys.argv) <= 1:
        eprint(f'usage: {os.path.basename(sys.argv[0])} file ...\n'
               f'       put back file(s) from Trash')
        sys.exit(64)  # what rm does with no args

    exitcode = 0
    for arg in sys.argv[1:]:
        trash_path = Path(arg)

        try:
            orig_path = getxattr(trash_path, ORIG_PATH_XATTR, symlink=True)
        except IOError:
            # getxattr doesn't distinguish failure modes
            if trash_path.exists():
                eprint(
                    f"{trash_path}: trashed file does not contain original path "
                    f"metadata; not restoring")
            else:
                eprint(f"{trash_path}: No such file or directory")
            exitcode = 1
            continue

        orig_path = Path(os.fsdecode(orig_path))
        orig_file = None
        try:
            if trash_path.is_dir() and not trash_path.is_symlink():
                orig_path.mkdir()
            else:
                orig_file = orig_path.open("x")
        except FileExistsError:
            if orig_path.is_dir() and not orig_path.is_symlink():
                eprint(f"{orig_path}: already exists as a dir; not restoring")
                exitcode = 1
                continue
            eprint(f"overwrite {orig_path}? (y/n [n])")
            res = input()
            if res[0] != "y":
                eprint("not overwritten")
                exitcode = 1
                continue

        trash_path.replace(orig_path)
        eprint(f"{orig_path}\n")
        removexattr(orig_path, ORIG_PATH_XATTR, symlink=True)
        if orig_file:
            orig_file.close()

    sys.exit(exitcode)
示例#48
0
def check_user_xattr(path):
    if not os_path.exists(path):
        return False
    try:
        xattr.setxattr(path, 'user.test.key1', 'value1')
    except IOError as err:
        raise GlusterFileSystemIOError(
            err.errno,
            'xattr.setxattr("%s", "user.test.key1", "value1")' % (path,))
    try:
        xattr.removexattr(path, 'user.test.key1')
    except IOError as err:
        logging.exception("check_user_xattr: remove failed on %s err: %s",
                          path, str(err))
        #Remove xattr may fail in case of concurrent remove.
    return True
示例#49
0
 def delete_xattr(self, name, silent=True):
     """
     Deletes the extended attribute with the specified name from this file.
     If the attribute does not exist and silent is true, nothing will
     happen. If the attribute does not exist and silent is false, an
     exception will be thrown.
     
     The same compatibility warnings present on list_xattrs apply here.
     """
     import xattr
     try:
         xattr.removexattr(self.path, name)
     except IOError as e:
         if (e.errno == errno.ENODATA or e.errno == errno.EOPNOTSUPP
                 or e.errno == errno.ENOENT) and silent: # Attribute doesn't exist
             # and silent is true; do nothing.
             pass
         else:
             raise
示例#50
0
 def test_xattr(self):
     fn = os.path.join(self.mount_point, str(uuid.uuid4()))
     try:
         with open(fn, 'wb') as f:
             f.write('hello\n')
         x = xattr.xattr(fn)
         x.set('abc', 'def')
         x.set('123', '456')
         self.unmount()
         self.mount()
         self.assertEqual(x.get('abc'), 'def')
         self.assertEqual(set(x.list()), {'abc', '123'})
         xattr.removexattr(fn, 'abc')
         self.assertEqual(set(x.list()), {'123'})
     finally:
         try:
             os.remove(fn)
         except EnvironmentError:
             pass
示例#51
0
  def unlink(self, path):
    print 'unlink', path
    tags = path.split("/")[1:-1] # hmmm
    fname = path.split("/")[-1]
    full = fullpath[fname]

    print tags
    xalist = xattr.listxattr(full)

    for tag in tags:
      xa = "user.%s" % tag

      if xa in xalist:
        xattr.removexattr(full, xa)

      if full in backend[tag]:
        backend[tag].remove(full)

    return 0
示例#52
0
 def remove_attr(self, attrname):
     """ Remove a raw attribute and value from this file.
         Returns True on success.
         Possibly raises AttrError.
     """
     try:
         xattr.removexattr(
             self.filepath,
             attrname,
             symlink=self.follow_symlinks)
     except EnvironmentError as ex:
         if ex.errno == self.errno_nodata:
             # Already removed.
             return True
         raise self.AttrError(
             'Unable to remove attribute \'{}\' for: {}\n{}'.format(
                 attrname,
                 self.filepath,
                 ex))
     return True
示例#53
0
    (option, args) = parser.parse_args()
    if not args:
        print ("Usage: setfattr {-n name} [-v value] file...")
        print ("       setfattr {-x name} file...")
        print ("Try `setfattr --help' for more information.")
        sys.exit(1)

    if option.name and option.xname:
        print ("-n and -x are mutually exclusive...")
        sys.exit(1)

    if option.name:
        if option.value is None:
            print ("-n option requires -v value...")

    args[0] = os.path.abspath(args[0])

    if option.name and option.value:
        try:
            xattr.setxattr(args[0], option.name, convert(option.value))
        except Exception as err:
            print (err)
            sys.exit(1)

    if option.xname:
        try:
            xattr.removexattr(args[0], option.xname)
        except Exception as err:
            print (err)
            sys.exit(1)
示例#54
0
def do_removexattr(path, key):
    xattr.removexattr(path, key)
示例#55
0
文件: fs.py 项目: danielfullmer/nzbfs
 def removexattr(self, path, name):
     return xattr.removexattr(self.db_root + path, name)
示例#56
0
    def removexattr(self, path, key):
        import xattr

        return xattr.removexattr(self.real_path(path), key)
示例#57
0
        	''' set attrs, get attrs and remove attrs for a dir '''

                os.mkdir(TESTDIR, 0755)
		try:
			xattr.setxattr(TESTDIR, DIR_ATTR, DIR_ATTR_VAL)
		except IOError, e:
			print e
                	os.rmdir(TESTDIR)
			raise e

                got_attr = xattr.getxattr(TESTDIR, DIR_ATTR)
		self.assertEqual(got_attr, DIR_ATTR_VAL, 'Error: attributes'
				 'mismatch')
                xattr.listxattr(TESTDIR)
                xattr.removexattr(TESTDIR, DIR_ATTR)
                os.rmdir(TESTDIR)

        ''' POSIX ACL tests - setfacl, getfacl '''

	@unittest.skipUnless(has_posix1e, "requires posix1e module")

        def test_file_posix_acl(self):

        	''' set POSIX acl, get remove ACL on a file '''

                f = open(TESTFILE, 'w')
                facl = posix1e.ACL(text=FACL_TO_SET)
                facl.applyto(TESTFILE)
		got_acl = posix1e.ACL(file=TESTFILE)
                f.close()