@@ -376,21 +376,37 @@ def _remove_dist(dist, paths=sys.path):
376376
377377
378378def remove (project_name , paths = sys .path , auto_confirm = True ):
379- """Removes a single project from the installation"""
379+ """Removes a single project from the installation.
380+
381+ Returns True on success
382+ """
380383 dist = get_distribution (project_name , use_egg_info = True , paths = paths )
381384 if dist is None :
382385 raise PackagingError ('Distribution "%s" not found' % project_name )
383386 files = dist .list_installed_files (local = True )
384387 rmdirs = []
385388 rmfiles = []
386389 tmp = tempfile .mkdtemp (prefix = project_name + '-uninstall' )
390+
391+ def _move_file (source , target ):
392+ try :
393+ os .rename (source , target )
394+ except OSError as err :
395+ return err
396+ return None
397+
398+ success = True
399+ error = None
387400 try :
388401 for file_ , md5 , size in files :
389402 if os .path .isfile (file_ ):
390403 dirname , filename = os .path .split (file_ )
391404 tmpfile = os .path .join (tmp , filename )
392405 try :
393- os .rename (file_ , tmpfile )
406+ error = _move_file (file_ , tmpfile )
407+ if error is not None :
408+ success = False
409+ break
394410 finally :
395411 if not os .path .isfile (file_ ):
396412 os .rename (tmpfile , file_ )
@@ -401,6 +417,11 @@ def remove(project_name, paths=sys.path, auto_confirm=True):
401417 finally :
402418 shutil .rmtree (tmp )
403419
420+ if not success :
421+ logger .info ('%r cannot be removed.' , project_name )
422+ logger .info ('Error: %s' % str (error ))
423+ return False
424+
404425 logger .info ('Removing %r: ' , project_name )
405426
406427 for file_ in rmfiles :
@@ -447,6 +468,8 @@ def remove(project_name, paths=sys.path, auto_confirm=True):
447468 logger .info ('Success: removed %d files and %d dirs' ,
448469 file_count , dir_count )
449470
471+ return True
472+
450473
451474def install (project ):
452475 logger .info ('Getting information about %r...' , project )
0 commit comments