Edgewall Software
Modify

Opened 16 years ago

Last modified 15 years ago

#253 new defect

rmtree problem (again :-( ) on windows

Reported by: thomas_mueller_ffb Owned by: osimons
Priority: major Milestone: 0.6.1
Component: Build slave Version: dev
Keywords: rmtree Cc:
Operating System: Windows

Description (last modified by osimons)

Traceback (most recent call last):
  File "C:\Python25\Scripts\bitten-slave-script.py", line 8, in <module>
    load_entry_point('Bitten==0.6dev-r521', 'console_scripts', 'bitten-slave')()

  File "c:\python25\lib\site-packages\Bitten-0.6dev_r521-py2.5.egg\bitten\slave.
py", line 381, in main
    slave.run()
  File "c:\python25\lib\site-packages\Bitten-0.6dev_r521-py2.5.egg\bitten\slave.
py", line 150, in run
    self._create_build()
  File "c:\python25\lib\site-packages\Bitten-0.6dev_r521-py2.5.egg\bitten\slave.
py", line 195, in _create_build
    self._initiate_build(resp.info().get('location'))
  File "c:\python25\lib\site-packages\Bitten-0.6dev_r521-py2.5.egg\bitten\slave.
py", line 207, in _initiate_build
    self._execute_build(build_url, resp)
  File "c:\python25\lib\site-packages\Bitten-0.6dev_r521-py2.5.egg\bitten\slave.
py", line 238, in _execute_build
    _rmtree(basedir)
  File "c:\python25\lib\site-packages\Bitten-0.6dev_r521-py2.5.egg\bitten\slave.
py", line 43, in _rmtree
    return shutil.rmtree(root, onerror=_handle_error)
  File "C:\Python25\lib\shutil.py", line 169, in rmtree
    rmtree(fullname, ignore_errors, onerror)
  File "C:\Python25\lib\shutil.py", line 169, in rmtree
    rmtree(fullname, ignore_errors, onerror)
  File "C:\Python25\lib\shutil.py", line 178, in rmtree
    onerror(os.rmdir, path, sys.exc_info())
  File "c:\python25\lib\site-packages\Bitten-0.6dev_r521-py2.5.egg\bitten\slave.
py", line 42, in _handle_error
    fn(path)
WindowsError: [Error 145] The directory is not empty: 'c:\\docume~1\\deepdi~1\\l
ocals~1\\temp\\bittenufirfj\\build_Qt4.2_6\\deploy\\.svn'

Attachments (0)

Change History (4)

comment:1 Changed 15 years ago by osimons

  • Description modified (diff)
  • Owner changed from cmlenz to osimons

This I've seen before... Subversion makes various files inside a working copy read-only, and shutil.rmtree on Windows won't remove read-only files, and hence directories will not be empty when expected to.

I've got some utility code for another project that wraps rmtree, and if OS is Windows it walks all files and turns off read-only before removing:

import shutil, os
def rmtree(path, *args, **kwargs):
    if os.name == 'nt':
        for (dirpath, dirnames, filenames) in os.walk(path):
            # Windows does not allow remove of read-only files
            for filename in filenames:
                os.chmod(os.path.join(dirpath, filename),
                            stat.S_IWRITE)
    shutil.rmtree(path, *args, **kwargs)

I'll see if I can make a patch to actually test this.

comment:2 Changed 15 years ago by osimons

Right. So [521] contains a fix for shutil.rmtree(), and from the traceback it seems you are running that version and still see the error. It seems like that fix sets permissions, but I'm not quite sure that catches a read-only flag on the file in Windows.

Could you please also try to add this line:

  • bitten/slave.py

    a b  
    4343    """Catch shutil.rmtree failures on Windows when files are read-only, and only remove if root exists."""
    4444    def _handle_error(fn, path, excinfo):
    4545       os.chmod(path, 0666)
     46       os.chmod(path, stat.S_IWRITE)
    4647       fn(path)
    4748    if os.path.exists(root):
    4849        return shutil.rmtree(root, onerror=_handle_error)

comment:3 Changed 15 years ago by osimons

Sorry, forgot the line to include import stat in previous patch. And as the two os.chmod() calls try to do the same it would be interesting just to try the latest:

  • bitten/slave.py

    a b  
    2020import socket
    2121import tempfile
    2222import time
     23import stat
    2324
    2425from bitten.build import BuildError
    2526from bitten.build.config import Configuration
     
    4243def _rmtree(root):
    4344    """Catch shutil.rmtree failures on Windows when files are read-only, and only remove if root exists."""
    4445    def _handle_error(fn, path, excinfo):
    45        os.chmod(path, 0666)
     46       os.chmod(path, stat.S_IWRITE)
    4647       fn(path)
    4748    if os.path.exists(root):
    4849        return shutil.rmtree(root, onerror=_handle_error)

comment:4 Changed 15 years ago by osimons

  • Milestone changed from 0.6 to 0.6.1

Add Comment

Modify Ticket

Change Properties
Set your email in Preferences
Action
as new The owner will remain osimons.
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.