##// END OF EJS Templates
appendfile: handle only changelog.i file
Matt Mackall -
r4260:bdbfc219 default
parent child Browse files
Show More
@@ -105,43 +105,41 b' class appendopener(object):'
105 105
106 106 def __init__(self, opener):
107 107 self.realopener = opener
108 # key: file name, value: appendfile name
109 self.tmpnames = {}
108 self.tmpname = None
110 109
111 110 def __call__(self, name, mode='r'):
112 111 '''open file.'''
113
112 # only handle .i file
113 if not name.endswith("."):
114 return self.realopener(name, mode)
114 115 assert mode in 'ra+'
115 116 try:
116 117 realfp = self.realopener(name, 'r')
117 118 except IOError, err:
118 119 if err.errno != errno.ENOENT: raise
119 realfp = self.realopener(name, 'w+')
120 tmpname = self.tmpnames.get(name)
121 fp = appendfile(realfp, tmpname)
120 self.realfp = self.realopener(name, 'w+')
121 fp = appendfile(realfp, self.tmpname)
122 122 if tmpname is None:
123 self.tmpnames[name] = fp.tmpname
123 self.tmpname = fp.tmpname
124 self.name = name
124 125 return fp
125 126
126 127 def writedata(self):
127 128 '''copy data from temp files to real files.'''
128 # write .d file before .i file.
129 tmpnames = self.tmpnames.items()
130 tmpnames.sort()
131 for name, tmpname in tmpnames:
132 ifp = open(tmpname, 'rb')
133 ofp = self.realopener(name, 'a')
134 for chunk in util.filechunkiter(ifp):
135 ofp.write(chunk)
136 ifp.close()
137 os.unlink(tmpname)
138 del self.tmpnames[name]
139 ofp.close()
129 if not self.tmpname:
130 return
131 ifp = open(self.tmpname, 'rb')
132 ofp = self.realopener(self.name, 'a')
133 for chunk in util.filechunkiter(ifp):
134 ofp.write(chunk)
135 ifp.close()
136 os.unlink(self.tmpname)
137 ofp.close()
140 138
141 139 def cleanup(self):
142 140 '''delete temp files (this discards unwritten data!)'''
143 for tmpname in self.tmpnames.values():
144 os.unlink(tmpname)
141 if self.tmpname:
142 os.unlink(self.tmpname)
145 143
146 144 # files for changelog and manifest are in different appendopeners, so
147 145 # not mixed up together.
General Comments 0
You need to be logged in to leave comments. Login now