bzr branch from svn+ssh fails on win32

Bug #524560 reported by methane
8
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Bazaar
Fix Released
Medium
Unassigned

Bug Description

bzr branch bzr+ssh://somehost/foo foo fails on win32.

This is because libsvn creates ssh child process and renaming pack file fails with PermissionDenied. (see below)
Attached patch opens file with 'O_NOINHERIT' flag. The flag avoids child process inherits bzr's file handles.

2010-02-19 22:55:31 +0900
0.234 bazaar version: 2.1.0
0.234 bzr arguments: [u'branch', u'svn+ssh://tr5/home/inada-n/svn/foo', u'bar']
0.250 looking for plugins in C:/Documents and Settings/inada-n/Application Data/bazaar/2.0/plugins
0.531 looking for plugins in C:\usr\Python2.6\lib\site-packages\bzrlib\plugins
0.531 Plugin name explorer already loaded
0.547 encoding stdout as sys.stdout encoding 'cp932'
4.638 bzr-svn: using Subversion 1.6.6 ()
4.872 potential branching layouts: [('root', 1)]
4.872 Guessed repository layout: RootLayout(), guess layout to use: RootLayout()
4.903 potential branching layouts: [('root', 1)]
4.903 Guessed repository layout: RootLayout(), guess layout to use: RootLayout()
4.997 creating repository in file:///C:/temp/bar/.bzr/.
8.557 Error suppressed by only_raises:
8.557 Traceback (most recent call last):
  File "C:\usr\Python2.6\lib\site-packages\bzrlib\decorators.py", line 222, in wrapped
    return unbound(*args, **kwargs)
  File "C:\usr\Python2.6\lib\site-packages\bzrlib\repofmt\pack_repo.py", line 2409, in unlock
    self.abort_write_group()
  File "C:\usr\Python2.6\lib\site-packages\bzrlib\repository.py", line 950, in abort_write_group
    self._abort_write_group()
  File "C:\usr\Python2.6\lib\site-packages\bzrlib\repofmt\pack_repo.py", line 2295, in _abort_write_group
    self._pack_collection._abort_write_group()
  File "C:\usr\Python2.6\lib\site-packages\bzrlib\repofmt\pack_repo.py", line 2110, in _abort_write_group
    operation.run_simple()
  File "C:\usr\Python2.6\lib\site-packages\bzrlib\cleanup.py", line 122, in run_simple
    self.cleanups, self.func, *args, **kwargs)
  File "C:\usr\Python2.6\lib\site-packages\bzrlib\cleanup.py", line 156, in _do_with_cleanups
    result = func(*args, **kwargs)
  File "C:\usr\Python2.6\lib\site-packages\bzrlib\repofmt\pack_repo.py", line 437, in abort
    self.write_stream.close()
  File "C:\usr\Python2.6\lib\site-packages\bzrlib\transport\__init__.py", line 242, in close
    del _file_streams[self.transport.abspath(self.relpath)]
KeyError: 'file:///C:/temp/bar/.bzr/repository/upload/cma5fyda21c1w7wbgksn.pack'

8.573 Traceback (most recent call last):
  File "C:\usr\Python2.6\lib\site-packages\bzrlib\commands.py", line 853, in exception_to_return_code
    return the_callable(*args, **kwargs)
  File "C:\usr\Python2.6\lib\site-packages\bzrlib\commands.py", line 1055, in run_bzr
    ret = run(*run_argv)
  File "C:\usr\Python2.6\lib\site-packages\bzrlib\commands.py", line 661, in run_argv_aliases
    return self.run_direct(**all_cmd_args)
  File "C:\usr\Python2.6\lib\site-packages\bzrlib\commands.py", line 665, in run_direct
    return self._operation.run_simple(*args, **kwargs)
  File "C:\usr\Python2.6\lib\site-packages\bzrlib\cleanup.py", line 122, in run_simple
    self.cleanups, self.func, *args, **kwargs)
  File "C:\usr\Python2.6\lib\site-packages\bzrlib\cleanup.py", line 156, in _do_with_cleanups
    result = func(*args, **kwargs)
  File "C:\usr\Python2.6\lib\site-packages\bzrlib\builtins.py", line 1232, in run
    source_branch=br_from)
  File "C:/Documents and Settings/inada-n/Application Data/bazaar/2.0/plugins\svn\remote.py", line 117, in sprout
    return super(SvnRemoteAccess, self).sprout(*args, **kwargs)
  File "C:\usr\Python2.6\lib\site-packages\bzrlib\bzrdir.py", line 1184, in sprout
    result_repo.fetch(source_repository, fetch_spec=fetch_spec)
  File "C:\usr\Python2.6\lib\site-packages\bzrlib\repository.py", line 1704, in fetch
    find_ghosts=find_ghosts, fetch_spec=fetch_spec)
  File "C:/Documents and Settings/inada-n/Application Data/bazaar/2.0/plugins\svn\fetch.py", line 1307, in fetch
    pack_hint = self._fetch_revisions(needed, pb)
  File "C:/Documents and Settings/inada-n/Application Data/bazaar/2.0/plugins\svn\fetch.py", line 1253, in _fetch_revisions
    use_replay=self._use_replay)
  File "C:/Documents and Settings/inada-n/Application Data/bazaar/2.0/plugins\svn\fetch.py", line 1243, in _fetch_revisions_nochunks
    hint = self.target.commit_write_group()
  File "C:\usr\Python2.6\lib\site-packages\bzrlib\repository.py", line 1563, in commit_write_group
    result = self._commit_write_group()
  File "C:\usr\Python2.6\lib\site-packages\bzrlib\repofmt\pack_repo.py", line 2314, in _commit_write_group
    hint = self._pack_collection._commit_write_group()
  File "C:\usr\Python2.6\lib\site-packages\bzrlib\repofmt\pack_repo.py", line 2157, in _commit_write_group
    self._new_pack.finish()
  File "C:\usr\Python2.6\lib\site-packages\bzrlib\repofmt\pack_repo.py", line 512, in finish
    self.upload_transport.rename(self.random_name, new_name)
  File "C:\usr\Python2.6\lib\site-packages\bzrlib\transport\local.py", line 425, in rename
    self._translate_error(e, path_from)
  File "C:\usr\Python2.6\lib\site-packages\bzrlib\transport\__init__.py", line 318, in _translate_error
    raise errors.PermissionDenied(path, extra=e)
PermissionDenied: Unprintable exception PermissionDenied: dict={'path': u'C:/temp/bar/.bzr/repository/upload/cma5fyda21c1w7wbgksn.pack', '_preformatted_string': None, 'extra': ': [Error 32] \x83v\x83\x8d\x83Z\x83X\x82\xcd\x83t\x83@\x83C\x83\x8b\x82\xc9\x83A\x83N\x83Z\x83X\x82\xc5\x82\xab\x82\xdc\x82\xb9\x82\xf1\x81B\x95\xca\x82\xcc\x83v\x83\x8d\x83Z\x83X\x82\xaa\x8eg\x97p\x92\x86\x82\xc5\x82\xb7\x81B'}, fmt='Permission denied: "%(path)s"%(extra)s', error=UnicodeDecodeError('ascii', ': [Error 32] \x83v\x83\x8d\x83Z\x83X\x82\xcd\x83t\x83@\x83C\x83\x8b\x82\xc9\x83A\x83N\x83Z\x83X\x82\xc5\x82\xab\x82\xdc\x82\xb9\x82\xf1\x81B\x95\xca\x82\xcc\x83v\x83\x8d\x83Z\x83X\x82\xaa\x8eg\x97p\x92\x86\x82\xc5\x82\xb7\x81B', 13, 14, 'ordinal not in range(128)')

Related branches

Revision history for this message
methane (songofacandy) wrote :
Revision history for this message
Martin Pool (mbp) wrote :

Wow, that's great to see this solved. There may be some dupes of this, and perhaps we should look for other places where O_NOINHERIT should be used.

Revision history for this message
methane (songofacandy) wrote :

Maybe, only pipe in subprocess should not use O_NOINHERIT flag.
I've added osutils.open() in lp:~songofacandy/bzr/fix-524560

Revision history for this message
methane (songofacandy) wrote :

We should use osutils.open instead open when:
1. Child process can be created between open() and close(). And,
2. rename or remove the file after it is closed().

Revision history for this message
methane (songofacandy) wrote :

I've searched dangerous "rename", "delete" and "unlink" roughly.
I've found AtomicFile should use O_NOINHERIT too and fix it.

Martin Pool (mbp)
Changed in bzr:
status: New → In Progress
importance: Undecided → Medium
Vincent Ladeuil (vila)
Changed in bzr:
milestone: none → 2.0.5
methane (songofacandy)
Changed in bzr:
status: In Progress → Fix Committed
Revision history for this message
Martin Pool (mbp) wrote :

I think this is now fixed

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.