From 909bc181885185a6ee96f34a2fb3ad5ffb92954e Mon Sep 17 00:00:00 2001 From: Guido van Rossum Date: Sun, 3 Jan 1999 13:06:00 +0000 Subject: Recover from failed saves; when a file turns out to be a directory, create a directory and moer the original file to the index.html. --- Tools/webchecker/websucker.py | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/Tools/webchecker/websucker.py b/Tools/webchecker/websucker.py index 59da51b..67e493d 100755 --- a/Tools/webchecker/websucker.py +++ b/Tools/webchecker/websucker.py @@ -73,10 +73,13 @@ class Sucker(webchecker.Checker): def savefile(self, text, path): dir, base = os.path.split(path) makedirs(dir) - f = open(path, "wb") - f.write(text) - f.close() - self.message("saved %s", path) + try: + f = open(path, "wb") + f.write(text) + f.close() + self.message("saved %s", path) + except IOError, msg: + self.message("didn't save %s: %s", path, str(msg)) def savefilename(self, url): type, rest = urllib.splittype(url) @@ -93,7 +96,16 @@ class Sucker(webchecker.Checker): return path def makedirs(dir): - if not dir or os.path.exists(dir): + if not dir: + return + if os.path.exists(dir): + if not os.path.isdir(dir): + try: + os.rename(dir, dir + ".bak") + os.mkdir(dir) + os.rename(dir + ".bak", os.path.join(dir, "index.html")) + except os.error: + pass return head, tail = os.path.split(dir) if not tail: -- cgit v0.12