Пример #1
0
    def action_create(self):
        path = self.resource.path

        if not sudo.path_exists(path):
            Logger.info("Creating directory %s since it doesn't exist." %
                        self.resource)

            # dead links should be followed, else we gonna have failures on trying to create directories on top of them.
            if self.resource.follow:
                # Follow symlink until the tail.
                followed_links = set()
                while sudo.path_islink(path):
                    if path in followed_links:
                        raise Fail(
                            "Applying %s failed, looped symbolic links found while resolving %s"
                            % (self.resource, path))
                    followed_links.add(path)
                    prev_path = path
                    path = sudo.readlink(path)

                    if not os.path.isabs(path):
                        path = os.path.join(os.path.dirname(prev_path), path)

                if path != self.resource.path:
                    Logger.info(
                        "Following the link {0} to {1} to create the directory"
                        .format(self.resource.path, path))

            if self.resource.create_parents:
                sudo.makedirs(path, self.resource.mode or 0755)
            else:
                dirname = os.path.dirname(path)
                if not sudo.path_isdir(dirname):
                    raise Fail(
                        "Applying %s failed, parent directory %s doesn't exist"
                        % (self.resource, dirname))

                try:
                    sudo.makedir(path, self.resource.mode or 0755)
                except Exception as ex:
                    # race condition (somebody created the file before us)
                    if "File exists" in str(ex):
                        sudo.makedirs(path, self.resource.mode or 0755)
                    else:
                        raise

        if not sudo.path_isdir(path):
            raise Fail("Applying %s failed, file %s already exists" %
                       (self.resource, path))

        _ensure_metadata(
            path,
            self.resource.owner,
            self.resource.group,
            mode=self.resource.mode,
            cd_access=self.resource.cd_access,
            recursive_ownership=self.resource.recursive_ownership,
            recursive_mode_flags=self.resource.recursive_mode_flags,
            recursion_follow_links=self.resource.recursion_follow_links,
            safemode_folders=self.resource.safemode_folders)
Пример #2
0
  def action_create(self):
    path = self.resource.path

    if not sudo.path_exists(path):
      Logger.info("Creating directory %s since it doesn't exist." % self.resource)
      
      # dead links should be followed, else we gonna have failures on trying to create directories on top of them.
      if self.resource.follow:
        # Follow symlink until the tail.
        followed_links = set()
        while sudo.path_lexists(path):
          if path in followed_links:
            raise Fail("Applying %s failed, looped symbolic links found while resolving %s" % (self.resource, path))
          followed_links.add(path)
          path = sudo.readlink(path)
          
        if path != self.resource.path:
          Logger.info("Following the link {0} to {1} to create the directory".format(self.resource.path, path))

      if self.resource.create_parents:
        sudo.makedirs(path, self.resource.mode or 0755)
      else:
        dirname = os.path.dirname(path)
        if not sudo.path_isdir(dirname):
          raise Fail("Applying %s failed, parent directory %s doesn't exist" % (self.resource, dirname))
        
        sudo.makedir(path, self.resource.mode or 0755)
      
    if not sudo.path_isdir(path):
      raise Fail("Applying %s failed, file %s already exists" % (self.resource, path))
    
    _ensure_metadata(path, self.resource.owner, self.resource.group,
                        mode=self.resource.mode, cd_access=self.resource.cd_access,
                        recursive_ownership=self.resource.recursive_ownership, recursive_mode_flags=self.resource.recursive_mode_flags, 
                        recursion_follow_links=self.resource.recursion_follow_links, safemode_folders=self.resource.safemode_folders)
Пример #3
0
  def action_create(self):
    path = self.resource.path

    if not sudo.path_exists(path):
      Logger.info("Creating directory %s since it doesn't exist." % self.resource)
      
      # dead links should be followed, else we gonna have failures on trying to create directories on top of them.
      if self.resource.follow:
        # Follow symlink until the tail.
        followed_links = set()
        while sudo.path_lexists(path):
          if path in followed_links:
            raise Fail("Applying %s failed, looped symbolic links found while resolving %s" % (self.resource, path))
          followed_links.add(path)
          path = sudo.readlink(path)
          
        if path != self.resource.path:
          Logger.info("Following the link {0} to {1} to create the directory".format(self.resource.path, path))

      if self.resource.recursive:
        sudo.makedirs(path, self.resource.mode or 0755)
      else:
        dirname = os.path.dirname(path)
        if not sudo.path_isdir(dirname):
          raise Fail("Applying %s failed, parent directory %s doesn't exist" % (self.resource, dirname))
        
        sudo.makedir(path, self.resource.mode or 0755)
      
    if not sudo.path_isdir(path):
      raise Fail("Applying %s failed, file %s already exists" % (self.resource, path))
    
    _ensure_metadata(path, self.resource.owner, self.resource.group,
                        mode=self.resource.mode, cd_access=self.resource.cd_access)