diff --git a/pisi/archive.py b/pisi/archive.py index e45a083a..d6912216 100644 --- a/pisi/archive.py +++ b/pisi/archive.py @@ -533,7 +533,7 @@ class ArchiveZip(ArchiveBase): continue # check that output dir is present - util.check_dir(os.path.dirname(ofile)) + util.ensure_dirs(os.path.dirname(ofile)) # remove output file we might be overwriting. # (also check for islink? for broken symlinks...) diff --git a/pisi/config.py b/pisi/config.py index 798555f6..91fa0d67 100644 --- a/pisi/config.py +++ b/pisi/config.py @@ -90,7 +90,8 @@ class Config(object): def subdir(self, path): subdir = pisi.util.join_path(self.dest_dir(), path) - pisi.util.check_dir(subdir) + if os.access(os.path.dirname(subdir), os.W_OK): + pisi.util.ensure_dirs(subdir) return subdir def log_dir(self): diff --git a/pisi/fetcher.py b/pisi/fetcher.py index e7ca5cac..251e1063 100644 --- a/pisi/fetcher.py +++ b/pisi/fetcher.py @@ -118,8 +118,7 @@ class Fetcher: self.partial_file = self.archive_file + ctx.const.partial_suffix self.progress = None - util.check_dir(self.destdir) - + util.ensure_dirs(self.destdir) def fetch (self): """Return value: Fetched file's full path..""" diff --git a/pisi/file.py b/pisi/file.py index dc88e83f..2ce8a84f 100644 --- a/pisi/file.py +++ b/pisi/file.py @@ -105,6 +105,8 @@ class File: assert isinstance(uri, pisi.uri.URI) + pisi.util.ensure_dirs(transfer_dir) + if sha1sum: sha1filename = File.download(pisi.uri.URI(uri.get_uri() + '.sha1sum'), transfer_dir) sha1f = file(sha1filename) diff --git a/pisi/index.py b/pisi/index.py index c4f9167f..d436c42e 100644 --- a/pisi/index.py +++ b/pisi/index.py @@ -63,7 +63,8 @@ class Index(xmlfile.XmlFile): else: tmpdir = os.path.join(ctx.config.tmp_dir(), 'index') pisi.util.clean_dir(tmpdir) - pisi.util.check_dir(tmpdir) + + pisi.util.ensure_dirs(tmpdir) # write uri urlfile = file(pisi.util.join_path(tmpdir, 'uri'), 'w') diff --git a/pisi/package.py b/pisi/package.py index 5dbec245..06f6edda 100644 --- a/pisi/package.py +++ b/pisi/package.py @@ -189,7 +189,7 @@ class Package: """Extract file with path to outdir""" data = self.impl.read_file(path) fpath = util.join_path(outdir, path) - util.check_dir(os.path.dirname(fpath)) + util.ensure_dirs(os.path.dirname(fpath)) with open(fpath, "wb") as f: f.write(data) diff --git a/pisi/util.py b/pisi/util.py index 5b2f3a55..bd1350ee 100644 --- a/pisi/util.py +++ b/pisi/util.py @@ -343,13 +343,10 @@ def check_file(file, mode = os.F_OK): raise FileError("File " + file + " not found") return True -# FIXME: check_dir is not a good name considering it can also create the dir -def check_dir(d): - """Make sure given directory path exists.""" - # FIXME: What is first strip doing there? - d = d.strip().rstrip("/") - if not os.access(d, os.F_OK): - os.makedirs(d) +def ensure_dirs(path): + """Make sure the given directory path exists.""" + if not os.path.exists(path): + os.makedirs(path) def clean_dir(path): """Remove all content of a directory.""" @@ -386,13 +383,13 @@ def dir_size(dir): def copy_file(src,dest): """Copy source file to the destination file.""" check_file(src) - check_dir(os.path.dirname(dest)) + ensure_dirs(os.path.dirname(dest)) shutil.copyfile(src, dest) def copy_file_stat(src,dest): """Copy source file to the destination file with all stat info.""" check_file(src) - check_dir(os.path.dirname(dest)) + ensure_dirs(os.path.dirname(dest)) shutil.copy2(src, dest) def read_link(link): @@ -615,7 +612,7 @@ def strip_file(filepath, fileinfo, outpath): elif "SB executable" in fileinfo: if ctx.config.values.build.generatedebug: - check_dir(os.path.dirname(outpath)) + ensure_dirs(os.path.dirname(outpath)) save_elf_debug(filepath, outpath) run_strip(filepath) # FIXME: removing RPATH also causes problems, for details see gelistirici mailing list - caglar10ur @@ -624,7 +621,7 @@ def strip_file(filepath, fileinfo, outpath): elif "SB shared object" in fileinfo: if ctx.config.values.build.generatedebug: - check_dir(os.path.dirname(outpath)) + ensure_dirs(os.path.dirname(outpath)) save_elf_debug(filepath, outpath) run_strip(filepath, "--strip-unneeded") # run_chrpath(filepath)