summaryrefslogtreecommitdiffstats
path: root/pym/portage/util/_path.py
blob: 6fbcb438c4b1f6ccb83c6091ff8048cb222b4cf7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# Copyright 2013 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2

import stat

from portage import os
from portage.exception import PermissionDenied

def exists_raise_eaccess(path):
	try:
		os.stat(path)
	except OSError as e:
		if e.errno == PermissionDenied.errno:
			raise PermissionDenied("stat('%s')" % path)
		return False
	else:
		return True

def isdir_raise_eaccess(path):
	try:
		st = os.stat(path)
	except OSError as e:
		if e.errno == PermissionDenied.errno:
			raise PermissionDenied("stat('%s')" % path)
		return False
	else:
		return stat.S_ISDIR(st.st_mode)