Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Warn on access denied errors when deleting from lib-bkp during uninstall #263

Closed
vorou opened this issue May 1, 2015 · 15 comments
Closed

Comments

@vorou
Copy link

vorou commented May 1, 2015

It happens after my chocolateyUninstall.ps1 is finished. I've tried to log handles, didn't find the file there. I can remove it manually after uninstalling is finished.

Attempting to delete directory "C:\ProgramData\chocolatey\lib-bkp\rbtray".
This is try 1/3. Retrying after 300 milliseconds.
 Error converted to warning:
 System.UnauthorizedAccessException: Access to the path 'RBHook.dll' is denied.
   at System.IO.Directory.DeleteHelper(String fullPath, String userPath, Boolean recursive, Boolean throwOnTopLevelDirectoryNotFound)
   at System.IO.Directory.Delete(String fullPath, String userPath, Boolean recursive, Boolean checkHost)
   at chocolatey.infrastructure.tolerance.FaultTolerance.<>c__DisplayClass1.<retry>b__0()
   at chocolatey.infrastructure.tolerance.FaultTolerance.retry[T](Int32 numberOfTries, Func`1 function, Int32 waitDurationMilliseconds, Int32 increaseRetryByMilliseconds)
This is try 2/3. Retrying after 400 milliseconds.
 Error converted to warning:
 System.UnauthorizedAccessException: Access to the path 'RBHook.dll' is denied.
   at System.IO.Directory.DeleteHelper(String fullPath, String userPath, Boolean recursive, Boolean throwOnTopLevelDirectoryNotFound)
   at System.IO.Directory.Delete(String fullPath, String userPath, Boolean recursive, Boolean checkHost)
   at chocolatey.infrastructure.tolerance.FaultTolerance.<>c__DisplayClass1.<retry>b__0()
   at chocolatey.infrastructure.tolerance.FaultTolerance.retry[T](Int32 numberOfTries, Func`1 function, Int32 waitDurationMilliseconds, Int32 increaseRetryByMilliseconds)
Maximum tries of 3 reached. Throwing error.
Attempted to remove 'C:\ProgramData\chocolatey\lib-bkp\rbtray' but had an error::
 System.UnauthorizedAccessException: Access to the path 'RBHook.dll' is denied.
   at System.IO.Directory.DeleteHelper(String fullPath, String userPath, Boolean recursive, Boolean throwOnTopLevelDirectoryNotFound)
   at System.IO.Directory.Delete(String fullPath, String userPath, Boolean recursive, Boolean checkHost)
   at chocolatey.infrastructure.tolerance.FaultTolerance.<>c__DisplayClass1.<retry>b__0()
   at chocolatey.infrastructure.tolerance.FaultTolerance.retry[T](Int32 numberOfTries, Func`1 function, Int32 waitDurationMilliseconds, Int32 increaseRetryByMilliseconds)
   at chocolatey.infrastructure.tolerance.FaultTolerance.<>c__DisplayClass4.<try_catch_with_logging_exception>b__3()
   at chocolatey.infrastructure.tolerance.FaultTolerance.try_catch_with_logging_exception[T](Func`1 function, String errorMessage, Boolean throwError, Boolean logWarningInsteadOfError)
@ferventcoder
Copy link
Member

Is there a service or something locking the file?

@ferventcoder
Copy link
Member

Can you include the full log please?

@ferventcoder
Copy link
Member

We tend to move the files over to lib-bkp, which allows locked files to go because they are not being deleted. Then when it tries to delete the file, something is still holding a lock on it. Perhaps it would be better to warn in that folder...

@vorou
Copy link
Author

vorou commented May 2, 2015

Can you include the full log please?

https://gist.github.com/vorou/4c084bb3165c26412a08

@vorou
Copy link
Author

vorou commented May 2, 2015

Found that you need admin rights to delete the DLL. Didn't notice it earlier since I was in admin PowerShell. When I'm trying to delete the file in Explorer, it shows the dialog asking for permissions, and then remove the file.

So, I created removedll.ps1:

Write-Output "Removing the DLLs..."
rm 'C:\ProgramData\chocolatey\lib\rbtray\tools\64bit\RBHook.dll'
rm 'C:\ProgramData\chocolatey\lib-bkp\rbtray\tools\64bit\RBHook.dll'
Write-Output "DLLs removed."

And I call it from uninstall script like so:

$toolsDir ="$(Split-Path -parent $MyInvocation.MyCommand.Definition)"
Start-ChocolateyProcessAsAdmin "& $($toolsDir)\removedll.ps1"

It finishes w/o any errors, but then same stuff happens. Choco can't remove the file in lib-bkp, and afterwards I can see the files just like nobody was removing them. It's sooo strange.

Here's the full log for this one.

@vorou
Copy link
Author

vorou commented May 9, 2015

I almost gave up on getting rid of the error messages, but noticed that the uninstall script doesn't remove lib\rbtray folder. So, after uninstall I have lib\rbtray folder untouched, and a newly created copy of RBHook.dll in lib-bkp\rbtray.

Here's my chocolateyUninstall.ps1. What am I doing wrong?

@qzo
Copy link

qzo commented Jun 20, 2015

I have the exact same problem with a ZIP app containing a read-only file. I get warning during install and uninstall processes, but after the installation is finished, everything seems to be OK. But after uninstall, the read-only file is still present in both lib and lib-bkp.
The package in question is:
https://github.com/qzo/chocolatey-packages/tree/6b892168b853ce537cf9f1b25aa2009f5f266a5a/packages/manual/farr_m/find-and-run-robot.portable
Logs:
https://gist.github.com/qzo/e4965ecdbb6e8ca773a3
https://gist.github.com/qzo/5e77b1844f87b4bef915

@ferventcoder
Copy link
Member

@qzo The stop process - how does that work with upgrades?

@ferventcoder
Copy link
Member

Is it possible that the process isn't fully stopped yet, so it's still locking the files. You may want to insert about a second or two of sleep in there to ensure that the process is fully stopped.

@ferventcoder
Copy link
Member

And do a try catch instead of silently continuing, so you can log out any errors that are found, like the process not shutting down.

@qzo
Copy link

qzo commented Jun 20, 2015

But the application process isn't running at all - it can't run before the installation and I also checked it didn't run before uninstall, but I got the warnings anyway. I'm 99 % sure it has to do with the file in question having read-only attribute.

The Stop-Process isn't really relevant - I just didn't want upgrade / uninstall to fail due to the application still running. But I just found out uninstall causes the process to close, so maybe it's not necessary after all.

@ferventcoder
Copy link
Member

Good point on read only attributes. Let's file a new issue on that.

@qzo
Copy link

qzo commented Jun 20, 2015

Here you go: #338

@ferventcoder ferventcoder added this to the 0.9.9.9 milestone Jun 30, 2015
@ferventcoder ferventcoder changed the title Failed to delete a .dll from lib-bkp during uninstall (access denied) Warn on access denied errors when deleting from lib-bkp during uninstall Jun 30, 2015
@ferventcoder
Copy link
Member

Looks like this was switched to a warning awhile ago - 217e8fa#diff-03afb4ba12230f0f345a29a934727585R356

@ferventcoder
Copy link
Member

I'm going to close this one as part of #338 fixes. If this comes back up as not fixed in 0.9.9.9, please feel free to comment and we can reopen.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants