def save(self):
        """Write changed .pth file back to disk"""
        # first reload the file
        last_paths, last_dirty = self._load()
        # and check that there are no difference with what we have.
        # there can be difference if someone else has written to the file
        # since we first loaded it.
        # we don't want to lose the eventual new paths added since then.
        for path in last_paths[:]:
            if path not in self.paths:
                self.paths.append(path)
                log.info("detected new path %r", path)
                last_dirty = True
            else:
                last_paths.remove(path)
        # also, re-check that all paths are still valid before saving them
        for path in self.paths[:]:
            if path not in last_paths and not path.startswith(
                ('import ', 'from ', '#')
            ):
                absolute_path = os.path.join(self.basedir, path)
                if not os.path.exists(absolute_path):
                    self.paths.remove(path)
                    log.info("removing now non-existent path %r", path)
                    last_dirty = True

        self.dirty |= last_dirty or self.paths != self._init_paths
        if not self.dirty:
            return

        rel_paths = list(map(self.make_relative, self.paths))
        if rel_paths:
            log.debug("Saving %s", self.filename)
            lines = self._wrap_lines(rel_paths)
            data = '\n'.join(lines) + '\n'
            if os.path.islink(self.filename):
                os.unlink(self.filename)
            with open(self.filename, 'wt') as f:
                f.write(data)
        elif os.path.exists(self.filename):
            log.debug("Deleting empty %s", self.filename)
            os.unlink(self.filename)

        self.dirty = False
        self._init_paths[:] = self.paths[:]
Write changed .pth file back to disk
product/gradle-plugin/src/main/python/setuptools/command/easy_install.py