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

WindowsError: [Error 5] Access is denied #2

Closed
Peter-Maguire opened this issue Jan 2, 2017 · 11 comments
Closed

WindowsError: [Error 5] Access is denied #2

Peter-Maguire opened this issue Jan 2, 2017 · 11 comments

Comments

@Peter-Maguire
Copy link

Traceback (most recent call last): File "trufflehog.py", line 106, in <module> find_strings(args.git_url) File "trufflehog.py", line 98, in find_strings shutil.rmtree(project_path) File "C:\Python27\lib\shutil.py", line 247, in rmtree rmtree(fullname, ignore_errors, onerror) File "C:\Python27\lib\shutil.py", line 247, in rmtree rmtree(fullname, ignore_errors, onerror) File "C:\Python27\lib\shutil.py", line 247, in rmtree rmtree(fullname, ignore_errors, onerror) File "C:\Python27\lib\shutil.py", line 252, in rmtree onerror(os.remove, fullname, sys.exc_info()) File "C:\Python27\lib\shutil.py", line 250, in rmtree os.remove(fullname) WindowsError: [Error 5] Access is denied: 'temp\\[uuid]\\.git\\objects\\pack\\pack-[uuid].idx'

When scanning some repos. (This one crashes half way through, This one crashes at startup)

@dxa4481
Copy link
Collaborator

dxa4481 commented Jan 2, 2017

I haven't tried running it in windows, I'll spin up a VM later today and see what I can do

@dxa4481
Copy link
Collaborator

dxa4481 commented Jan 2, 2017

I changed the way the temp files are being used, can you try again and see if you still get the error?

Neither repository is throwing exceptions for me currently.

@bandrel
Copy link

bandrel commented Jan 3, 2017

I'm still getting the access is denied

Traceback (most recent call last): File "truffleHog.py", line 119, in <module> find_strings(args.git_url) File "truffleHog.py", line 111, in find_strings shutil.rmtree(project_path) File "C:\Python27\lib\shutil.py", line 247, in rmtree rmtree(fullname, ignore_errors, onerror) File "C:\Python27\lib\shutil.py", line 247, in rmtree rmtree(fullname, ignore_errors, onerror) File "C:\Python27\lib\shutil.py", line 247, in rmtree rmtree(fullname, ignore_errors, onerror) File "C:\Python27\lib\shutil.py", line 252, in rmtree onerror(os.remove, fullname, sys.exc_info()) File "C:\Python27\lib\shutil.py", line 250, in rmtree os.remove(fullname) WindowsError: [Error 5] Access is denied: 'c:\\users\\myuser\\appdata\\local\\temp\\tmpeujqhn\\.git\\objects\\0a\\fbcb182e8f0d6f75e99159d4b47dc28122e70'

@ryanohoro
Copy link

The problem is in the git module, it's holding open the file handles and I've found no way to close them without monkeypatching the git module.

I work around the problem by not bothering to delete the temporary directories:

    try: # This delete will fail in Windows when the repo object does not release its file handles
        shutil.rmtree(project_path)
    except Exception as e:
        pass

@bandrel
Copy link

bandrel commented Jan 3, 2017

its a combination of holding the directory open and shutil.rmtree() not being able to remove read only files. The pr should fix both issues.

@leozulfiu
Copy link

Just cloned the repo and started it in cygwin. I get this error:

Traceback (most recent call last):
  File "truffleHog.py", line 119, in <module>
    find_strings(args.git_url)
  File "truffleHog.py", line 111, in find_strings
    shutil.rmtree(project_path)
  File "C:\Users\lezu\AppData\Local\Programs\Python\Python36-32\lib\shutil.py", line 488, in rmtree
    return _rmtree_unsafe(path, onerror)
  File "C:\Users\lezu\AppData\Local\Programs\Python\Python36-32\lib\shutil.py", line 378, in _rmtree_                                     unsafe
    _rmtree_unsafe(fullname, onerror)
  File "C:\Users\lezu\AppData\Local\Programs\Python\Python36-32\lib\shutil.py", line 378, in _rmtree_                                     unsafe
    _rmtree_unsafe(fullname, onerror)
  File "C:\Users\lezu\AppData\Local\Programs\Python\Python36-32\lib\shutil.py", line 378, in _rmtree_                                     unsafe
    _rmtree_unsafe(fullname, onerror)
  File "C:\Users\lezu\AppData\Local\Programs\Python\Python36-32\lib\shutil.py", line 383, in _rmtree_                                     unsafe
    onerror(os.unlink, fullname, sys.exc_info())
  File "C:\Users\lezu\AppData\Local\Programs\Python\Python36-32\lib\shutil.py", line 381, in _rmtree_                                     unsafe
    os.unlink(fullname)
PermissionError: [WinError 5] Access is denied: 'C:\\cygwin64\\tmp\\tmp2fio9ety\\.git\\objects\\0a\\f                                     bcb182e8f0d6f75e99159d4b478dc28122e70'

@bandrel
Copy link

bandrel commented Jan 4, 2017

I did not test in cygwin, but i'm having trouble installing the dependencies in cygwin with having them installed outside of cygwin. Could you, @leozulfiu, please test my PR #15 to see if it fixes your issue?

@dxa4481 dxa4481 closed this as completed Feb 26, 2017
@dxa4481
Copy link
Collaborator

dxa4481 commented Feb 26, 2017

closing bc I think #15 took care of this

@ghost
Copy link

ghost commented Mar 24, 2017

I am still facing this issue when deleting directory via python in windows

def local_delete_directory(dirname):
	print "Deleting local directory: " + dirname
	try:
		for root, dirs, files in os.walk(dirname, topdown=False):
			for name in files:
				os.remove(os.path.join(root, name))
			for name in dirs:
				os.rmdir(os.path.join(root, name))
	except Exception,ex:
		print "exception" + str(ex)
	print "Finished deleting local directory"

exception[Error 5] Access is denied: u'1490323408\.git\objects\pack\pack-ece
d52b66ccb22ccfe8386d69bd8070101b9c106.idx'

@natelongstreet
Copy link

Currently having the same issue against a local repo.
Trying to run 'trufflehog --regex --entropy=false
Traceback (most recent call last): File "C:\Users\<userID>\AppData\Local\Programs\Python\Python38\Scripts\trufflehog-script.py", line 11, in <module> load_entry_point('truffleHog==2.0.92', 'console_scripts', 'trufflehog')() File "C:\Users\<userID>\AppData\Local\Programs\Python\Python38\lib\site-packages\trufflehog-2.0.92-py3.8.egg\truffleHog\truffleHog.py", line 57, in main File "C:\Users\<userID>\AppData\Local\Programs\Python\Python38\lib\site-packages\trufflehog-2.0.92-py3.8.egg\truffleHog\truffleHog.py", line 302, in find_strings File "C:\Users\<userID>\AppData\Local\Programs\Python\Python38\lib\shutil.py", line 681, in rmtree return _rmtree_unsafe(path, onerror) File "C:\Users\<userID>\AppData\Local\Programs\Python\Python38\lib\shutil.py", line 560, in _rmtree_unsafe _rmtree_unsafe(fullname, onerror) File "C:\Users\<userID>\AppData\Local\Programs\Python\Python38\lib\shutil.py", line 560, in _rmtree_unsafe _rmtree_unsafe(fullname, onerror) File "C:\Users\<userID>\AppData\Local\Programs\Python\Python38\lib\shutil.py", line 560, in _rmtree_unsafe _rmtree_unsafe(fullname, onerror) File "C:\Users\<userID>\AppData\Local\Programs\Python\Python38\lib\shutil.py", line 565, in _rmtree_unsafe onerror(os.unlink, fullname, sys.exc_info()) File "C:\Users\<userID>\AppData\Local\Programs\Python\Python38\lib\site-packages\trufflehog-2.0.92-py3.8.egg\truffleHog\truffleHog.py", line 83, in del_rw PermissionError: [WinError 5] Access is denied: 'C:\\Temp\\tmpx1kphjv8\\.git\\objects\\pack\\pack-<uuid>.idx'
I even set TEMP folder permissions on windows to Everyone Full to rule out weird folder permission errors. I also am running it as administrator as well.

@mterron
Copy link

mterron commented Nov 21, 2019

This is still happening for me on linux. .git/objects/pack has d-w------- permissions and --cleanup fails with: OSError: [Errno 39] Directory not empty: pack and
IsADirectoryError: [Errno 21] Is a directory: '/tmp/tmpsdfhskj32342/.git.objects/pack'

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

No branches or pull requests

7 participants