Bazaar tries to write 0-length strings to files

Bug #162930 reported by John A Meinel
2
Affects Status Importance Assigned to Milestone
Bazaar
Fix Released
High
Robert Collins

Bug Description

There are a few places where we might try to create an empty file.

Often this is done using Transport.put_bytes('') or Transport.put_bytes_non_atomic('').
In either case we end up doing something like:
  os.write(fd, '')

It seems that on Mac OS X, when you mount a Samba share, this fails. I'm not sure why it is the only place that doesn't like writing 0 bytes to a file.

This works around it at the Local transport layer. Such that we don't try to write a zero length string:

=== modified file 'bzrlib/transport/local.py'
--- bzrlib/transport/local.py 2007-10-04 22:00:07 +0000
+++ bzrlib/transport/local.py 2007-11-15 18:06:02 +0000
@@ -185,7 +185,8 @@
         except (IOError, OSError),e:
             self._translate_error(e, path)
         try:
- fp.write(bytes)
+ if bytes:
+ fp.write(bytes)
             fp.commit()
         finally:
             fp.close()
@@ -265,8 +266,12 @@

     def put_bytes_non_atomic(self, relpath, bytes, mode=None,
                              create_parent_dir=False, dir_mode=None):
- def writer(fd):
- os.write(fd, bytes)
+ if bytes:
+ def writer(fd):
+ os.write(fd, bytes)
+ else:
+ def writer(fd):
+ pass #Nothing to write
         self._put_non_atomic_helper(relpath, writer, mode=mode,
                                     create_parent_dir=create_parent_dir,
                                     dir_mode=dir_mode)

Revision history for this message
John A Meinel (jameinel) wrote :

The fix seems small, though the bug only shows up under odd circumstances.

Changed in bzr:
importance: Undecided → High
status: New → Triaged
Martin Pool (mbp)
Changed in bzr:
status: Triaged → In Progress
Revision history for this message
Martin Pool (mbp) wrote :

This is a pretty obscure bug, but since you've written the patch shall we merge it?

The patch looks ok. I would wonder if treetransform and other things that write to the workingtree would suffer similar problems...

Revision history for this message
Robert Collins (lifeless) wrote :

I imagine that they would, yes.

Changed in bzr:
assignee: nobody → Robert Collins (lifeless)
status: In Progress → Fix Committed
Revision history for this message
Martin Pool (mbp) wrote :

The branch claims to be merged, is this fixreleased?

Revision history for this message
Robert Collins (lifeless) wrote : Re: [Bug 162930] Re: Bazaar tries to write 0-length strings to files

 status fixreleased

Changed in bzr:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.