예제 #1
0
def test_removexattr(setup_unreliablefs, symlink):
    mnt_dir, src_dir = setup_unreliablefs
    name = name_generator()
    src_name = pjoin(src_dir, name)
    mnt_name = pjoin(mnt_dir, name)
    os_create(mnt_name)
    linkname = name_generator()
    link_path = os.path.join(mnt_dir, linkname)
    os.symlink(mnt_dir, link_path)
    if symlink:
        target = link_path
    else:
        target = mnt_name

    attr_value = b"unreliablefs"
    attr_name = b"user.fsname"

    os.setxattr(target, attr_name, attr_value)
    assert attr_name.decode("utf-8") in os.listxattr(target)
    assert os.getxattr(target, attr_name) == attr_value
    os.removexattr(target, attr_name)
    try:
        assert os.getxattr(target, attr_name) == None
    except OSError:
        pass
예제 #2
0
파일: acl_linux.py 프로젝트: yaplej/freenas
    def _strip_acl_posix1e(self, path):
        posix_xattrs = ['system.posix_acl_access', 'system.posix_acl_default']
        for xat in os.listxattr(path):
            if xat not in posix_xattrs:
                continue

            os.removexattr(path, xat)
예제 #3
0
파일: fusefs.py 프로젝트: mgorny/fusebox
 async def removexattr(self, vnode, name_enced, ctx):
     name = os.fsdecode(name_enced)
     path = self.vm[vnode].path
     try:
         os.removexattr(path, name)
     except OSError as exc:
         raise pyfuse3.FUSEError(exc.errno)
예제 #4
0
 async def removexattr(self, inode: INode, name: bytes,
                       ctx: RequestContext) -> None:
     try:
         os.removexattr(path=self.paths[inode],
                        attribute=name,
                        follow_symlinks=False)
     except OSError as exc:
         raise FUSEError(exc.errno) from None
예제 #5
0
 def remove_remote_id_impl(path: Path, name: str = "ndrive") -> None:
     """Remove a given extended attribute."""
     try:
         os.removexattr(path, f"user.{name}")  # type: ignore
     except OSError as exc:
         # EPROTONOSUPPORT: protocol not supported (xattr)
         # ENODATA: no data available
         if exc.errno not in (errno.ENODATA, errno.EPROTONOSUPPORT):
             raise exc
예제 #6
0
def rmxattr(_endpoint, filepath, _userid, key):
    '''Remove the extended attribute <key> on behalf of the given userid'''
    try:
        os.removexattr(_getfilepath(filepath), 'user.' + key)
    except (FileNotFoundError, PermissionError, OSError) as e:
        log.warning(
            'msg="Failed to rmxattr" filepath="%s" key="%s" exception="%s"' %
            (filepath, key, e))
        raise IOError(e)
예제 #7
0
    def __delitem__(self, k: str) -> None:
        if not isinstance(k, KEY_TYPES):
            raise TypeError(f"Xattr keys must be str, not {type(k).__name__}")

        try:
            removexattr(self.path, k, follow_symlinks=self.follow_symlinks)
        except OSError as e:
            if e.errno == MISSING_KEY_ERRNO:
                raise KeyError(k) from None
            raise
예제 #8
0
    def remove_for_file(
        cls,
        path: Union[int, str, bytes, "os.PathLike[str]", "os.PathLike[bytes]"],
    ) -> None:
        """
        Removes the file capabilities attached to the given file. ``path`` is as for
        ``os.removexattr()``.
        """

        os.removexattr(path, ffi.XATTR_NAME_CAPS)
예제 #9
0
    def removexattr(self, path, name):
        logging.debug("removexattr: %s", repr((path, name)))
        src_path = self.getSource(path)

        if name == xattr_revisions_name:
            raise (fuse.FuseOSError(errno.EACCES))

        file_info = FileInfo()
        if src_path in self.files:
            file_info = self.files
        else:
            file_info.loadFileInfo(src_path)

        if name == xattr_max_revisions_name:
            if file_info.revisions != max_revisions:
                if max_revisions < file_info.revisions:
                    file_info.setMaxRevisions(revisions)
                    f = File(src_path,
                             os.path.isdir(src_path, follow_symlinks=False))
                    f.limitRevisions(file_info)
                else:
                    file_info.setMaxRevisions(revisions)

                file_info.saveFileInfo(src_path)
            return

        if name == xattr_max_revision_age:
            if file_info.max_age != max_revision_age:
                if max_revision_age < file_info.max_age:
                    file_info.setMaxRevisionAge(max_revision_age)
                    f = File(src_path,
                             os.path.isdir(src_path, follow_symlinks=False))
                    f.limitRevisions(file_info)
                else:
                    file_info.setMaxRevisionAge(max_revision_age)

                file_info.saveFileInfo(src_path)
            return

        if name == xattr_min_revisions_age:
            if file_info.min_revisions != min_revisions_age:
                if min_revisions_age < file_info.min_revisions:
                    file_info.setMinRevisionsAge(min_revisions_age)
                    f = File(src_path,
                             os.path.isdir(src_path, follow_symlinks=False))
                    f.limitRevisions(file_info)
                else:
                    file_info.setMinRevisionsAge(min_revisions_age)

                file_info.saveFileInfo(src_path)
            return

        os.removexattr(src_path, name, follow_symlinks=False)
예제 #10
0
파일: file.py 프로젝트: shaneschulte/code
def set_file_attr(path, attr, value):
    try:
        if hasattr(path, "fileno"):
            path = path.fileno()
        if hasattr(value, "encode"):
            value = value.encode("utf-8")
        if value:
            os.setxattr(path, "user.%s" % attr, value)
        else:
            os.removexattr(path, "user.%s" % attr)
    except FileNotFoundError:
        raise
    except OSError:
        return
예제 #11
0
파일: noby.py 프로젝트: artizirk/noby
def build(args):
    context = Path(args.path).resolve()
    dockerfile = Path(args.file)
    if not dockerfile.is_absolute():
        dockerfile = context / dockerfile
    dockerfile = dockerfile.resolve()
    if not dockerfile.is_file():
        raise FileNotFoundError("{} does not exist".format(dockerfile))

    runtime = Path(args.runtime).resolve()
    r = ImageStorage(runtime)

    df = DockerfileParser(dockerfile)
    if not df.build_commands:
        print("Nothing to do")
        return

    if args.env:
        df.add_env_variables(args.env)

    #  Locate base image for this dockerfile
    parent_hash = ""
    if df.from_image != "scratch":
        parent_hash = r.find_last_build_by_name(df.from_image)
        if not parent_hash:
            raise FileNotFoundError("Image with name {} not found".format(df.from_image))
        print("Using parent image {}".format(parent_hash[:16]))

    #  Update build hashes based on base image
    df.calc_build_hashes(parent_hash=parent_hash)
    total_build_steps = len(df.build_commands)

    #  Early exit if image is already built
    if not args.no_cache and args.rm:
        if (runtime / df.build_hashes[-1]).exists():
            print("==> Already built {}".format(df.build_hashes[-1][:16]))
            return

    #  Do the build
    for current_build_step, (cmd, cmdargs) in enumerate(df.build_commands):
        build_step_hash = df.build_hashes[current_build_step]

        print("==> Building step {}/{} {}".format(current_build_step + 1, total_build_steps, build_step_hash[:16]))

        target = runtime / (build_step_hash + "-init")
        final_target = runtime / build_step_hash
        host_env = {
            "TARGET": str(target),
            "CONTEXT": str(context)
        }
        host_env.update(df.env)

        ## parent image checks
        if final_target.exists():
            if args.no_cache:
                btrfs_subvol_delete(final_target)
            else:
                previous_parent_hash = ""
                try:
                    previous_parent_hash = os.getxattr(str(final_target), b"user.parent_hash").decode()
                except:
                    pass
                if parent_hash and parent_hash != previous_parent_hash:
                    print("  -> parent image hash changed")
                    btrfs_subvol_delete(final_target)
                else:
                    print("  -> Using cached image")
                    parent_hash = build_step_hash
                    continue

        if target.exists():
            print("  -> Deleting incomplete image")
            btrfs_subvol_delete(target)

        if parent_hash:
            btrfs_subvol_snapshot(runtime / parent_hash, target)
        else:
            btrfs_subvol_create(target)

        ## Run build step
        if cmd == "host":
            print('  -> HOST {}'.format(cmdargs))
            subprocess.run(cmdargs, cwd=str(context), check=True, shell=True, env=host_env)

        elif cmd == "run":
            print('  -> RUN {}'.format(cmdargs))
            nspawn_cmd = ['systemd-nspawn', '--quiet']
            for key, val in df.env.items():
                nspawn_cmd.extend(('--setenv', '{}={}'.format(key, val)))
            nspawn_cmd.extend(('--register=no', '-D', str(target), '/bin/sh', '-c', cmdargs))
            subprocess.run(nspawn_cmd, cwd=str(target), check=True, shell=False, env=df.env)

        elif cmd == "copy":
            print("  -> COPY {}".format(cmdargs))
            *srcs, dest = shlex.split(cmdargs)
            if Path(dest).is_absolute():
                dest = target / dest[1:]
            else:
                dest = target / dest
            if len(srcs) > 1 and not dest.is_dir():
                raise NotADirectoryError("Destination must be a directory")
            cmd = ['cp', '-rv']
            cmd.extend(srcs)
            cmd.append(str(dest))
            subprocess.run(cmd, cwd=str(context), check=True, shell=False, env=host_env)

        ## Seal build image
        os.setxattr(str(target), b"user.parent_hash", parent_hash.encode())
        for attr in ("user.cmd.host", "user.cmd.run"):
            try:
                os.removexattr(str(target), attr.encode())
            except:
                pass
        os.setxattr(str(target), "user.cmd.{}".format(cmd).encode(), cmdargs.encode())

        btrfs_subvol_snapshot(target, final_target, readonly=True)
        btrfs_subvol_delete(target)

        parent_hash = build_step_hash

    #  After build cleanup
    if args.rm:
        print("==> Cleanup")
        for build_hash in df.build_hashes[:-1]:
            target = runtime / build_hash
            if target.exists():
                print("  -> Remove intermediate image {}".format(build_hash[:16]))
                btrfs_subvol_delete(target)

    print("==> Successfully built {}".format(parent_hash[:16]))

    if args.tag:
        tmp_tag = runtime / ("tag-" + args.tag + "-tmp")
        if tmp_tag.exists():
            os.unlink(str(tmp_tag))
        os.symlink(str(runtime / parent_hash), str(tmp_tag))
        os.replace(str(tmp_tag), str(runtime / ("tag-" + args.tag)))
        print("==> Tagged image {} as {}".format(parent_hash[:16], args.tag))
예제 #12
0
def build(args):
    context = Path(args.path).resolve()
    dockerfile = Path(args.file)
    if not dockerfile.is_absolute():
        dockerfile = context / dockerfile
    dockerfile = dockerfile.resolve()
    if not dockerfile.is_file():
        raise FileNotFoundError("{} does not exist".format(dockerfile))

    runtime = Path(args.runtime).resolve()
    r = ImageStorage(runtime)

    df = DockerfileParser(dockerfile)
    if not df.build_commands:
        print("Nothing to do")
        return

    if args.env:
        df.add_env_variables(args.env)

    #  Locate base image for this dockerfile
    parent_hash = ""
    if df.from_image != "scratch":
        parent_hash = r.find_last_build_by_name(df.from_image)
        if not parent_hash:
            raise FileNotFoundError("Image with name {} not found".format(
                df.from_image))
        print("Using parent image {}".format(parent_hash[:16]))

    #  Update build hashes based on base image
    df.calc_build_hashes(parent_hash=parent_hash)
    total_build_steps = len(df.build_commands)

    #  Early exit if image is already built
    if not args.no_cache and args.rm:
        if (runtime / df.build_hashes[-1]).exists():
            print("==> Already built {}".format(df.build_hashes[-1][:16]))
            return

    #  Do the build
    for current_build_step, (cmd, cmdargs) in enumerate(df.build_commands):
        build_step_hash = df.build_hashes[current_build_step]

        print("==> Building step {}/{} {}".format(current_build_step + 1,
                                                  total_build_steps,
                                                  build_step_hash[:16]))

        target = runtime / (build_step_hash + "-init")
        final_target = runtime / build_step_hash
        host_env = {"TARGET": str(target), "CONTEXT": str(context)}
        host_env.update(df.env)

        ## parent image checks
        if final_target.exists():
            if args.no_cache:
                btrfs_subvol_delete(final_target)
            else:
                previous_parent_hash = ""
                try:
                    previous_parent_hash = os.getxattr(
                        str(final_target), b"user.parent_hash").decode()
                except:
                    pass
                if parent_hash and parent_hash != previous_parent_hash:
                    print("  -> parent image hash changed")
                    btrfs_subvol_delete(final_target)
                else:
                    print("  -> Using cached image")
                    parent_hash = build_step_hash
                    continue

        if target.exists():
            print("  -> Deleting incomplete image")
            btrfs_subvol_delete(target)

        if parent_hash:
            btrfs_subvol_snapshot(runtime / parent_hash, target)
        else:
            btrfs_subvol_create(target)

        ## Run build step
        if cmd == "host":
            print('  -> HOST {}'.format(cmdargs))
            subprocess.run(cmdargs,
                           cwd=str(context),
                           check=True,
                           shell=True,
                           env=host_env)

        elif cmd == "run":
            print('  -> RUN {}'.format(cmdargs))
            nspawn_cmd = ['systemd-nspawn', '--quiet']
            for key, val in df.env.items():
                nspawn_cmd.extend(('--setenv', '{}={}'.format(key, val)))
            nspawn_cmd.extend(
                ('--register=no', '-D', str(target), '/bin/sh', '-c', cmdargs))
            subprocess.run(nspawn_cmd,
                           cwd=str(target),
                           check=True,
                           shell=False,
                           env=df.env)

        elif cmd == "copy":
            print("  -> COPY {}".format(cmdargs))
            *srcs, dest = shlex.split(cmdargs)
            if Path(dest).is_absolute():
                dest = target / dest[1:]
            else:
                dest = target / dest
            if len(srcs) > 1 and not dest.is_dir():
                raise NotADirectoryError("Destination must be a directory")
            cmd = ['cp', '-rv']
            cmd.extend(srcs)
            cmd.append(str(dest))
            subprocess.run(cmd,
                           cwd=str(context),
                           check=True,
                           shell=False,
                           env=host_env)

        ## Seal build image
        os.setxattr(str(target), b"user.parent_hash", parent_hash.encode())
        for attr in ("user.cmd.host", "user.cmd.run"):
            try:
                os.removexattr(str(target), attr.encode())
            except:
                pass
        os.setxattr(str(target), "user.cmd.{}".format(cmd).encode(),
                    cmdargs.encode())

        btrfs_subvol_snapshot(target, final_target, readonly=True)
        btrfs_subvol_delete(target)

        parent_hash = build_step_hash

    #  After build cleanup
    if args.rm:
        print("==> Cleanup")
        for build_hash in df.build_hashes[:-1]:
            target = runtime / build_hash
            if target.exists():
                print("  -> Remove intermediate image {}".format(
                    build_hash[:16]))
                btrfs_subvol_delete(target)

    print("==> Successfully built {}".format(parent_hash[:16]))

    if args.tag:
        tmp_tag = runtime / ("tag-" + args.tag + "-tmp")
        if tmp_tag.exists():
            os.unlink(str(tmp_tag))
        os.symlink(str(runtime / parent_hash), str(tmp_tag))
        os.replace(str(tmp_tag), str(runtime / ("tag-" + args.tag)))
        print("==> Tagged image {} as {}".format(parent_hash[:16], args.tag))
예제 #13
0
파일: backup.py 프로젝트: r-nd-m/backup
 def clear_excess_file_atts(file: str, file_xatts: list):
     for xatt in file_xatts:
         os.removexattr(file, xatt)
예제 #14
0
 def remove(item, name, nofollow=False, namespace=None):
     return os.removexattr(item, name, follow_symlinks=not nofollow)
예제 #15
0
		def remove(item, name, nofollow=False, namespace=None):
			return os.removexattr(item, name, follow_symlinks=not nofollow)
예제 #16
0
os.walk("top")  # $ getAPathArgument="top"
os.walk(top="top")  # $ getAPathArgument="top"

os.fwalk("top")  # $ getAPathArgument="top"
os.fwalk(top="top")  # $ getAPathArgument="top"

# Linux only
os.getxattr("path", "attribute")  # $ getAPathArgument="path"
os.getxattr(path="path", attribute="attribute")  # $ getAPathArgument="path"

# Linux only
os.listxattr("path")  # $ getAPathArgument="path"
os.listxattr(path="path")  # $ getAPathArgument="path"

# Linux only
os.removexattr("path", "attribute")  # $ getAPathArgument="path"
os.removexattr(path="path", attribute="attribute")  # $ getAPathArgument="path"

# Linux only
os.setxattr("path", "attribute", "value")  # $ getAPathArgument="path"
os.setxattr(path="path", attribute="attribute",
            value="value")  # $ getAPathArgument="path"

# Windows only
os.add_dll_directory("path")  # $ getAPathArgument="path"
os.add_dll_directory(path="path")  # $ getAPathArgument="path"

# for `os.exec*`, `os.spawn*`, and `os.posix_spawn*` functions, see the
# `SystemCommandExecution.py` file.

# Windows only
예제 #17
0
def test_removing_xattrs(sub_done):
    fname = join(sub_done, 'hello')
    open(fname, 'w').close()

    with pytest.raises(OSError):
        os.removexattr(fname, 'user.cool_attr')
예제 #18
0
#!/usr/bin/env python3
import os
import sys
from selfdrive.loggerd.uploader import UPLOAD_ATTR_NAME

for fn in sys.argv[1:]:
    print(f"unmarking {fn}")
    os.removexattr(fn, UPLOAD_ATTR_NAME)
예제 #19
0
def rmxattr(_endpoint, filename, _ruid, _rgid, key):
  '''Remove the extended attribute <key> on behalf of the given uid, gid'''
  try:
    os.removexattr(_getfilename(filename), key)
  except (FileNotFoundError, PermissionError) as e:
    raise IOError(e)
예제 #20
0
    @staticmethod
    def get_path_remote_id(path: Path, /, *, name: str = "ndrive") -> str:
        """Get a given extended attribute from a file/folder."""
        try:
            return (os.getxattr(path, f"user.{name}").decode(
                "utf-8", errors="ignore")  # type: ignore
                    or "")
        except OSError:
            return ""

    @staticmethod
    def remove_remote_id_impl(path: Path, /, *, name: str = "ndrive") -> None:
        """Remove a given extended attribute."""
        try:
            os.removexattr(path, f"user.{name}")  # type: ignore
        except OSError as exc:
            # EPROTONOSUPPORT: protocol not supported (xattr)
            # ENODATA: no data available
            if exc.errno not in (errno.ENODATA, errno.EPROTONOSUPPORT):
                raise exc

    def set_folder_icon(self, ref: Path, icon: Path, /) -> None:
        """Use commandline to customize the folder icon."""
        folder = self.abspath(ref)

        # Emblems icons must be saved in $XDG_DATA_HOME/icons to be accessible
        emblem = self.shared_icons / "emblem-nuxeo.svg"
        emblem.parent.mkdir(parents=True, exist_ok=True)

        log.debug(f"Setting the folder emblem of {folder!r} using {emblem!r}")
예제 #21
0
def posix_removexattr(_: Context, path: Path, attr: str) -> None:
    os.removexattr(path, attr)
예제 #22
0
 def removexattr(self, path, name):
     p = self.realpath(path)
     return os.removexattr(p, name)