comparison MoinMoin/PageEditor.py @ 2841:93be75db2051

handle out-of-space errors in PageEditor and caching, avoid 'current' corruption (thanks to TheAnarcat)
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Wed, 19 Sep 2007 21:39:48 +0200
parents c4ab7c81146d
children 384135a7bb0a
comparison
equal deleted inserted replaced
2840:167c6efea1de 2841:93be75db2051
894 pagedir = self.getPagePath(use_underlay=0, check_create=0) 894 pagedir = self.getPagePath(use_underlay=0, check_create=0)
895 895
896 revdir = os.path.join(pagedir, 'revisions') 896 revdir = os.path.join(pagedir, 'revisions')
897 cfn = os.path.join(pagedir, 'current') 897 cfn = os.path.join(pagedir, 'current')
898 clfn = os.path.join(pagedir, 'current-locked') 898 clfn = os.path.join(pagedir, 'current-locked')
899 cltfn = os.path.join(pagedir, 'current-locked.tmp')
899 900
900 # !!! these log objects MUST be created outside the locked area !!! 901 # !!! these log objects MUST be created outside the locked area !!!
901 902
902 # The local log should be the standard edit log, not the 903 # The local log should be the standard edit log, not the
903 # underlay copy log! 904 # underlay copy log!
936 937
937 # increment rev number of current(-locked) page 938 # increment rev number of current(-locked) page
938 f = file(clfn) 939 f = file(clfn)
939 revstr = f.read() 940 revstr = f.read()
940 f.close() 941 f.close()
941 rev = int(revstr) 942 try:
943 rev = int(revstr)
944 except ValueError, err:
945 raise self.SaveError, _("Unable to determine current page revision from the 'current' file. The page %s is damaged and cannot be edited right now.") % self.page_name
946
942 if not was_deprecated: 947 if not was_deprecated:
943 if self.do_revision_backup or rev == 0: 948 if self.do_revision_backup or rev == 0:
944 rev += 1 949 rev += 1
945 revstr = '%08d' % rev 950 revstr = '%08d' % rev
946 f = file(clfn, 'w') 951 # write the current page rev to a temporary file
947 f.write(revstr+'\n') 952 try:
948 f.close() 953 f = file(cltfn, 'w')
954 f.write(revstr+'\n')
955 f.close()
956 except IOError, err:
957 try:
958 os.remove(cltfn)
959 except:
960 pass # we don't care for errors in the os.remove
961 # throw a nicer exception
962 if err.errno == errno.ENOSPC:
963 raise self.SaveError, _("Cannot save page %s, no storage space left.") % self.page_name
964 else:
965 raise self.SaveError, _("An I/O error occurred while saving page %s (errno=%d)") % (self.page_name, err.errno)
966 # atomically put it in place (except on windows)
967 else:
968 filesys.rename(cltfn, clfn)
949 969
950 if not deleted: 970 if not deleted:
951 # save to page file 971 # save to page file
952 pagefile = os.path.join(revdir, revstr) 972 pagefile = os.path.join(revdir, revstr)
953 f = codecs.open(pagefile, 'wb', config.charset) 973 f = codecs.open(pagefile, 'wb', config.charset)