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":
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:
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."""
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)
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
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):
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