def do(): # Mark all properties as dirty, so they can be added back # to the newly updated file. self.properties().update(self.properties()) backup = None if self._path.exists(): backup = hidden(self._path.temporarySibling()) self._path.moveTo(backup) fh = self._path.open("w") try: # FIXME: concurrency problem; if this write is interrupted # halfway through, the underlying file will be corrupt. fh.write(str(component)) finally: fh.close() # Now re-write the original properties on the updated file self.properties().flush() def undo(): if backup: backup.moveTo(self._path) else: self._path.remove() return undo
def do(): # Mark all properties as dirty, so they can be added back # to the newly updated file. self.properties().update(self.properties()) backup = None if self._path.exists(): backup = hidden(self._path.temporarySibling()) self._path.moveTo(backup) fh = self._path.open("w") try: # FIXME: concurrency problem; if this write is interrupted # halfway through, the underlying file will be corrupt. fh.write(componentText) finally: fh.close() md5 = hashlib.md5(componentText).hexdigest() self.properties()[md5key] = TwistedGETContentMD5.fromString(md5) # Now re-write the original properties on the updated file self.properties().flush() def undo(): if backup: backup.moveTo(self._path) else: self._path.remove() return undo
def createChildWithName(self, name): if name.startswith("."): raise HomeChildNameNotAllowedError(name) childPath = self._path.child(name) if name not in self._removedChildren and childPath.isdir(): raise HomeChildNameAlreadyExistsError(name) temporary = hidden(childPath.temporarySibling()) temporaryName = temporary.basename() temporary.createDirectory() # In order for the index to work (which is doing real file ops on disk # via SQLite) we need to create a real directory _immediately_. # FIXME: some way to roll this back. c = self._newChildren[name] = self._childClass(temporary.basename(), self, True, realName=name) c.retrieveOldIndex().create() def do(): childPath = self._path.child(name) temporary = childPath.sibling(temporaryName) try: props = c.properties() temporary.moveTo(childPath) c._name = name # FIXME: _lots_ of duplication of work here. props.flush() except (IOError, OSError), e: if e.errno == EEXIST and childPath.isdir(): raise HomeChildNameAlreadyExistsError(name) raise # FIXME: direct tests, undo for index creation # Return undo return lambda: self._path.child(childPath.basename()).remove()
def do(): backup = None if self._path.exists(): backup = hidden(self._path.temporarySibling()) self._path.moveTo(backup) fh = self._path.open("w") try: # FIXME: concurrency problem; if this write is interrupted # halfway through, the underlying file will be corrupt. fh.write(xmldata) finally: fh.close() def undo(): if backup: backup.moveTo(self._path) else: self._path.remove() return undo
def _create(cls, txn, home, collectionName): # FIXME: this is a near-copy of CommonHome.createChildWithName. temporary = hidden(home._path.child(collectionName).temporarySibling()) temporary.createDirectory() temporaryName = temporary.basename() c = cls(temporary.basename(), home) def do(): childPath = home._path.child(collectionName) temporary = childPath.sibling(temporaryName) try: props = c.properties() temporary.moveTo(childPath) c._name = collectionName # FIXME: _lots_ of duplication of work here. props.flush() except (IOError, OSError), e: if e.errno == EEXIST and childPath.isdir(): raise HomeChildNameAlreadyExistsError(collectionName) raise # FIXME: direct tests, undo for index creation # Return undo return lambda: home._path.child(collectionName).remove()