From: Zac Medico Date: Fri, 11 Apr 2008 03:28:02 +0000 (-0000) Subject: Copy group mode bits from $PKGDIR when creating subdirectories. X-Git-Tag: v2.1.5~198 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=145e756567e4caf443e6b6a27ec2d91c6731cb86;p=portage.git Copy group mode bits from $PKGDIR when creating subdirectories. (trunk r9827) svn path=/main/branches/2.1.2/; revision=9828 --- diff --git a/bin/emerge b/bin/emerge index e1ee662b1..cc4b8b27b 100755 --- a/bin/emerge +++ b/bin/emerge @@ -4960,6 +4960,12 @@ class MergeTask(object): bintree = self.trees[myroot]["bintree"] if bintree.populated: bintree.inject(pkg_key) + else: + # Copy group permissions for new directories that + # may have been created. + for path in ("All", portage.catsplit(pkg.cpv)[0]): + bintree._ensure_dir( + os.path.join(bintree.pkgdir, path)) if "--buildpkgonly" not in self.myopts: msg = " === (%s of %s) Merging (%s::%s)" % \ (mergecount, len(mymergelist), pkg_key, y) diff --git a/pym/portage.py b/pym/portage.py index 504c20f3f..94309a7c9 100644 --- a/pym/portage.py +++ b/pym/portage.py @@ -7835,12 +7835,7 @@ class binarytree(object): self._pkg_paths[mynewcpv] = os.path.join( *new_path.split(os.path.sep)[-2:]) if new_path != mytbz2: - try: - os.makedirs(os.path.dirname(new_path)) - except OSError, e: - if e.errno != errno.EEXIST: - raise - del e + self._ensure_dir(os.path.dirname(new_path)) _movefile(tbz2path, new_path, mysettings=self.settings) self._remove_symlink(mycpv) if new_path.split(os.path.sep)[-2] == "All": @@ -7873,12 +7868,7 @@ class binarytree(object): exist in the location of the symlink will first be removed.""" mycat, mypkg = catsplit(cpv) full_path = os.path.join(self.pkgdir, mycat, mypkg + ".tbz2") - try: - os.makedirs(os.path.dirname(full_path)) - except OSError, e: - if e.errno != errno.EEXIST: - raise - del e + self._ensure_dir(os.path.dirname(full_path)) try: os.unlink(full_path) except OSError, e: @@ -7922,6 +7912,26 @@ class binarytree(object): internal state for future calls to getname().""" self._move_to_all(cpv) + def _ensure_dir(self, path): + """ + Create the specified directory. Also, copy gid and group mode + bits from self.pkgdir if possible. + @param cat_dir: Absolute path of the directory to be created. + @type cat_dir: String + """ + try: + pkgdir_st = os.stat(self.pkgdir) + except OSError: + portage_util.ensure_dirs(path) + return + pkgdir_gid = pkgdir_st.st_gid + pkgdir_grp_mode = 02070 & pkgdir_st.st_mode + try: + portage_util.ensure_dirs(path, gid=pkgdir_gid, mode=pkgdir_grp_mode, mask=0) + except portage_exception.PortageException: + if not os.path.isdir(path): + raise + def _move_to_all(self, cpv): """If the file exists, move it. Whether or not it exists, update state for future getname() calls.""" @@ -7933,12 +7943,7 @@ class binarytree(object): except OSError, e: mystat = None if mystat and stat.S_ISREG(mystat.st_mode): - try: - os.makedirs(os.path.join(self.pkgdir, "All")) - except OSError, e: - if e.errno != errno.EEXIST: - raise - del e + self._ensure_dir(os.path.join(self.pkgdir, "All")) dest_path = os.path.join(self.pkgdir, "All", myfile) _movefile(src_path, dest_path, mysettings=self.settings) self._create_symlink(cpv) @@ -7952,12 +7957,7 @@ class binarytree(object): myfile = mypkg + ".tbz2" mypath = os.path.join(mycat, myfile) dest_path = os.path.join(self.pkgdir, mypath) - try: - os.makedirs(os.path.dirname(dest_path)) - except OSError, e: - if e.errno != errno.EEXIST: - raise - del e + self._ensure_dir(os.path.dirname(dest_path)) src_path = os.path.join(self.pkgdir, "All", myfile) _movefile(src_path, dest_path, mysettings=self.settings) self._pkg_paths[cpv] = mypath @@ -8093,6 +8093,7 @@ class binarytree(object): def inject(self,cpv): self.dbapi.cpv_inject(cpv) + self._ensure_dir(os.path.join(self.pkgdir, "All")) self._create_symlink(cpv) def exists_specific(self,cpv): @@ -8169,10 +8170,7 @@ class binarytree(object): writemsg("Resuming download of this tbz2, but it is possible that it is corrupt.\n", noiselevel=-1) mydest = self.pkgdir+"/All/" - try: - os.makedirs(mydest, 0775) - except (OSError, IOError): - pass + self._ensure_dir(mydest) from urlparse import urlparse # urljoin doesn't work correctly with unrecognized protocols like sftp url = self.settings["PORTAGE_BINHOST"].rstrip("/") + "/" + tbz2name