Exemplo n.º 1
0
    def action_create(self):
        path = self.resource.path

        if sudo.path_lexists(path):
            oldpath = os.path.realpath(path)
            if oldpath == self.resource.to:
                return
            if not sudo.path_lexists(path):
                raise Fail(
                    "%s trying to create a symlink with the same name as an existing file or directory"
                    % self.resource)
            Logger.info("%s replacing old symlink to %s" %
                        (self.resource, oldpath))
            sudo.unlink(path)

        if self.resource.hard:
            if not sudo.path_exists(self.resource.to):
                raise Fail(
                    "Failed to apply %s, linking to nonexistent location %s" %
                    (self.resource, self.resource.to))
            if sudo.path_isdir(self.resource.to):
                raise Fail(
                    "Failed to apply %s, cannot create hard link to a directory (%s)"
                    % (self.resource, self.resource.to))

            Logger.info("Creating hard %s" % self.resource)
            sudo.link(self.resource.to, path)
        else:
            if not sudo.path_exists(self.resource.to):
                Logger.info("Warning: linking to nonexistent location %s" %
                            self.resource.to)

            Logger.info("Creating symbolic %s to %s" %
                        (self.resource, self.resource.to))
            sudo.symlink(self.resource.to, path)
Exemplo n.º 2
0
  def action_create(self):
    path = self.resource.path

    if sudo.path_lexists(path):
      oldpath = os.path.realpath(path)
      if oldpath == self.resource.to:
        return
      if not sudo.path_lexists(path):
        raise Fail(
          "%s trying to create a symlink with the same name as an existing file or directory" % self.resource)
      Logger.info("%s replacing old symlink to %s" % (self.resource, oldpath))
      sudo.unlink(path)
      
    if self.resource.hard:
      if not sudo.path_exists(self.resource.to):
        raise Fail("Failed to apply %s, linking to nonexistent location %s" % (self.resource, self.resource.to))
      if sudo.path_isdir(self.resource.to):
        raise Fail("Failed to apply %s, cannot create hard link to a directory (%s)" % (self.resource, self.resource.to))
      
      Logger.info("Creating hard %s" % self.resource)
      sudo.link(self.resource.to, path)
    else:
      if not sudo.path_exists(self.resource.to):
        Logger.info("Warning: linking to nonexistent location %s" % self.resource.to)
        
      Logger.info("Creating symbolic %s to %s" % (self.resource, self.resource.to))
      sudo.symlink(self.resource.to, path)