Index: branches/ariel/xmldumps-backup/worker.py |
— | — | @@ -1122,13 +1122,25 @@ |
1123 | 1123 | link = self.dumpDir.latestPath(file) |
1124 | 1124 | if exists(link) or os.path.islink(link): |
1125 | 1125 | if os.path.islink(link): |
1126 | | - self.debug("Removing old symlink %s" % link) |
1127 | | - os.remove(link) |
| 1126 | + realfile = os.readlink(link) |
| 1127 | + # format of these links should be... ../20110228/elwikidb-20110228-templatelinks.sql.gz |
| 1128 | + rellinkpattern = re.compile('^\.\./(20[0-9]+)/'); |
| 1129 | + dateinlink = rellinkpattern.search(realfile) |
| 1130 | + if (dateinlink): |
| 1131 | + dateoflinkedfile = dateinlink.group(1) |
| 1132 | + dateinterval = int(self.date) - int(dateoflinkedfile) |
| 1133 | + else: |
| 1134 | + dateinterval = 0 |
| 1135 | + # no file or it's older than ours... *then* remove the link |
| 1136 | + if not exists(os.path.realpath(link)) or dateinterval > 0: |
| 1137 | + self.debug("Removing old symlink %s" % link) |
| 1138 | + os.remove(link) |
1128 | 1139 | else: |
1129 | 1140 | self.logAndPrint("What the hell dude, %s is not a symlink" % link) |
1130 | 1141 | raise BackupError("What the hell dude, %s is not a symlink" % link) |
1131 | 1142 | relative = relativePath(real, dirname(link)) |
1132 | | - if exists(real): |
| 1143 | + # if we removed the link cause it's obsolete, make the new one |
| 1144 | + if exists(real) and not exists(link): |
1133 | 1145 | self.debug("Adding symlink %s -> %s" % (link, relative)) |
1134 | 1146 | os.symlink(relative, link) |
1135 | 1147 | |