~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/branch.py

  • Committer: mbp at sourcefrog
  • Date: 2005-04-04 10:35:13 UTC
  • Revision ID: mbp@sourcefrog.net-20050404103513-d938ee5693d52989
merge win32 portability fixes

Show diffs side-by-side

added added

removed removed

Lines of Context:
162
162
        self.controlfile('README', 'w').write(
163
163
            "This is a Bazaar-NG control directory.\n"
164
164
            "Do not change any files in this directory.")
165
 
        self.controlfile('branch-format', 'w').write(BZR_BRANCH_FORMAT)
 
165
        self.controlfile('branch-format', 'wb').write(BZR_BRANCH_FORMAT)
166
166
        for d in ('text-store', 'inventory-store', 'revision-store'):
167
167
            os.mkdir(self.controlfilename(d))
168
168
        for f in ('revision-history', 'merged-patches',
179
179
 
180
180
        In the future, we might need different in-memory Branch
181
181
        classes to support downlevel branches.  But not yet.
182
 
        """        
183
 
        # read in binary mode to detect newline wierdness.
 
182
        """
 
183
        # This ignores newlines so that we can open branches created
 
184
        # on Windows from Linux and so on.  I think it might be better
 
185
        # to always make all internal files in unix format.
184
186
        fmt = self.controlfile('branch-format', 'rb').read()
 
187
        fmt.replace('\r\n', '')
185
188
        if fmt != BZR_BRANCH_FORMAT:
186
189
            bailout('sorry, branch format %r not supported' % fmt,
187
190
                    ['use a different bzr version',
209
212
        tmpf = file(tmpfname, 'w')
210
213
        inv.write_xml(tmpf)
211
214
        tmpf.close()
212
 
        os.rename(tmpfname, self.controlfilename('inventory'))
 
215
        inv_fname = self.controlfilename('inventory')
 
216
        if sys.platform == 'win32':
 
217
            os.remove(inv_fname)
 
218
        os.rename(tmpfname, inv_fname)
213
219
        mutter('wrote working inventory')
214
220
 
215
221
 
817
823
 
818
824
    def __del__(self):
819
825
        """Destroy the test branch, removing the scratch directory."""
820
 
        shutil.rmtree(self.base)
 
826
        try:
 
827
            shutil.rmtree(self.base)
 
828
        except OSError:
 
829
            # Work around for shutil.rmtree failing on Windows when
 
830
            # readonly files are encountered
 
831
            for root, dirs, files in os.walk(self.base, topdown=False):
 
832
                for name in files:
 
833
                    os.chmod(os.path.join(root, name), 0700)
 
834
            shutil.rmtree(self.base)
821
835
 
822
836
    
823
837