[entropy] ditch os.F_OK everywhere

This commit is contained in:
Fabio Erculiani
2009-09-05 14:35:55 +02:00
parent c469afeff7
commit b2149f5660
23 changed files with 87 additions and 58 deletions
+12 -9
View File
@@ -95,32 +95,34 @@ class ClientSystemSettingsPlugin(SystemSettingsPlugin):
keywords_path = os.path.join(repo_data['dbpath'],
etpConst['etpdatabasekeywordsfile'])
if os.access(maskpath, os.R_OK | os.F_OK):
if os.access(maskpath, os.R_OK) and os.path.isfile(maskpath):
repos_mask_setting[repoid] = maskpath
repos_mask_mtime[repoid] = dmp_dir + "/repo_" + \
repoid + "_" + etpConst['etpdatabasemaskfile'] + ".mtime"
if os.access(wlpath, os.R_OK | os.F_OK):
if os.access(wlpath, os.R_OK) and os.path.isfile(wlpath):
repos_lic_wl_setting[repoid] = wlpath
repos_lic_wl_mtime[repoid] = dmp_dir + "/repo_" + \
repoid + "_" + etpConst['etpdatabaselicwhitelistfile'] + \
".mtime"
if os.access(sm_path, os.R_OK | os.F_OK):
if os.access(sm_path, os.R_OK) and os.path.isfile(sm_path):
repos_sm_mask_setting[repoid] = sm_path
repos_sm_mask_mtime[repoid] = dmp_dir + "/repo_" + \
repoid + "_" + etpConst['etpdatabasesytemmaskfile'] + \
".mtime"
if os.access(ct_path, os.R_OK | os.F_OK):
if os.access(ct_path, os.R_OK) and os.path.isfile(ct_path):
confl_tagged[repoid] = ct_path
if os.access(critical_path, os.R_OK | os.F_OK):
if os.access(critical_path, os.R_OK) and \
os.path.isfile(critical_path):
repos_critical_updates_setting[repoid] = critical_path
repos_critical_updates_mtime[repoid] = dmp_dir + "/repo_" + \
repoid + "_" + etpConst['etpdatabasecriticalfile'] + \
".mtime"
if os.access(keywords_path, os.R_OK | os.F_OK):
if os.access(keywords_path, os.R_OK) and \
os.path.isfile(keywords_path):
repos_keywords_setting[repoid] = keywords_path
repos_keywords_mtime[repoid] = dmp_dir + "/repo_" + \
repoid + "_" + etpConst['etpdatabasekeywordsfile'] + \
@@ -172,7 +174,8 @@ class ClientSystemSettingsPlugin(SystemSettingsPlugin):
brf.flush()
brf.close()
if not os.access(old_branch_path, os.F_OK | os.R_OK):
if not os.access(old_branch_path, os.R_OK) and \
os.path.isfile(old_branch_path):
write_current_branch(current_branch)
return
@@ -216,7 +219,7 @@ class ClientSystemSettingsPlugin(SystemSettingsPlugin):
def delete_in_branch_upgrade():
br_path = etpConst['etp_in_branch_upgrade_file']
if os.access(br_path, os.W_OK | os.F_OK):
if os.access(br_path, os.W_OK) and os.path.isfile(br_path):
os.remove(br_path)
# actually execute this only if
@@ -426,7 +429,7 @@ class ClientSystemSettingsPlugin(SystemSettingsPlugin):
for repoid in repoids:
filepath = self.__repos_files['conflicting_tagged_packages'].get(
repoid)
if os.access(filepath, os.R_OK | os.F_OK):
if os.access(filepath, os.R_OK) and os.path.isfile(filepath):
confl_f = open(filepath,"r")
content = confl_f.readlines()
confl_f.close()
+3 -2
View File
@@ -1503,7 +1503,8 @@ class CalculatorsMixin:
# check if we are branch migrating
# in this case, critical pkgs feature is disabled
in_branch_upgrade = etpConst['etp_in_branch_upgrade_file']
if os.access(in_branch_upgrade, os.R_OK | os.F_OK):
if os.access(in_branch_upgrade, os.R_OK) and \
os.path.isfile(in_branch_upgrade):
return set(), []
db_digest = self.all_repositories_checksum()
@@ -1683,7 +1684,7 @@ class CalculatorsMixin:
# delete branch upgrade file if exists, since there are
# no updates, this file does not deserve to be saved anyway
br_path = etpConst['etp_in_branch_upgrade_file']
if os.access(br_path, os.W_OK | os.F_OK):
if os.access(br_path, os.W_OK) and os.path.isfile(br_path):
os.remove(br_path)
return update, remove, fine, spm_fine
@@ -753,7 +753,8 @@ class RepositoryMixin:
branch_mig_script = mydata['post_branch_hop_script']
branch_mig_md5sum = '0'
if os.access(branch_mig_script, os.R_OK | os.F_OK):
if os.access(branch_mig_script, os.R_OK) and \
os.path.isfile(branch_mig_script):
branch_mig_md5sum = self.entropyTools.md5sum(branch_mig_script)
const_debug_write(__name__,
@@ -863,7 +864,8 @@ class RepositoryMixin:
# check if branch upgrade script exists
branch_upg_script = mydata['post_branch_upgrade_script']
branch_upg_md5sum = '0'
if os.access(branch_upg_script, os.R_OK | os.F_OK):
if os.access(branch_upg_script, os.R_OK) and \
os.path.isfile(branch_upg_script):
branch_upg_md5sum = self.entropyTools.md5sum(branch_upg_script)
const_debug_write(__name__,
@@ -991,7 +993,7 @@ class MiscMixin:
f_obj.close()
MiscMixin.RESOURCES_LOCK_F_REF = None
if os.access(etpConst['locks']['using_resources'], os.F_OK):
if os.path.isfile(etpConst['locks']['using_resources']):
os.remove(etpConst['locks']['using_resources'])
def resources_check_lock(self):
@@ -39,7 +39,7 @@ class NoticeBoardMixin:
repo_data = self.SystemSettings['repositories']['available'][repoid]
nb_path = repo_data['local_notice_board']
if not os.access(nb_path, os.F_OK | os.R_OK):
if not os.access(nb_path, os.R_OK) and os.path.isfile(nb_path):
return {} # not found
# load RSS metadata and return if valid
@@ -65,7 +65,7 @@ class NoticeBoardMixin:
repo_data = self.SystemSettings['repositories']['available'][repoid]
nb_path = repo_data['local_notice_board_userdata']
if not os.access(nb_path, os.F_OK | os.R_OK):
if not os.access(nb_path, os.R_OK) and os.path.isfile(nb_path):
return {} # not found
# load metadata
@@ -1336,7 +1336,7 @@ class Package:
protected = False # file doesn't exist
# check if it's a text file
if protected and os.access(tofile, os.F_OK | os.R_OK):
if protected and os.path.isfile(tofile) and os.access(tofile, os.R_OK):
protected = entropy.tools.istextfile(tofile)
in_mask = protected
else:
@@ -2504,7 +2504,8 @@ class Package:
# if file exists, first checksum then fetch
down_path = os.path.join(etpConst['entropyworkdir'],
self.pkgmeta['download'])
if os.access(down_path, os.R_OK | os.F_OK):
if os.access(down_path, os.R_OK) and os.path.isfile(down_path):
# check size first
repo_size = dbconn.retrieveSize(idpackage)
f = open(down_path, "r")
@@ -346,7 +346,7 @@ class Repository:
mytxt = _("self.dbformat_eapi must be in (1,2)")
raise InvalidData('InvalidData: %s' % (mytxt,))
if not os.access(md5file, os.F_OK | os.R_OK):
if not (os.access(md5file, os.R_OK) and os.path.isfile(md5file)):
return -1
return self._verify_file_checksum(dbfile, md5file)
@@ -1056,7 +1056,8 @@ class Repository:
if (do_db_update_transfer is not None) and not \
do_db_update_transfer:
if os.access(dbfile, os.R_OK | os.W_OK | os.F_OK):
if os.access(dbfile, os.R_OK | os.W_OK) and \
os.path.isfile(dbfile):
try:
os.rename(dbfile, dbfile_old)
do_db_update_transfer = True
@@ -1129,7 +1130,7 @@ class Repository:
self.Entropy.cycleDone()
# remove garbage
if os.access(dbfile_old, os.R_OK | os.F_OK):
if os.access(dbfile_old, os.R_OK) and os.path.isfile(dbfile_old):
os.remove(dbfile_old)
# keep them closed
@@ -464,7 +464,7 @@ class Trigger:
for path in self._trigger_data['conftouch']:
path = etpConst['systemroot']+path
if not os.access(path, os.W_OK | os.F_OK):
if not os.access(path, os.W_OK) and os.path.isfile(path):
continue
try:
f_item = open(path, "abw")
@@ -478,7 +478,7 @@ class Trigger:
for item in self._trigger_data['initdisable']:
item = etpConst['systemroot'] + item
if not os.access(item, os.F_OK | os.W_OK):
if not os.access(item, os.W_OK) and os.path.isfile(item):
continue
myroot = "/"
@@ -625,7 +625,7 @@ class Trigger:
def __ebuild_setup_phase(self, ebuild, portage_atom):
rc = 0
env_file = self.pkgdata['unpackdir']+"/portage/"+portage_atom+"/temp/environment"
if not os.access(env_file, os.R_OK | os.F_OK):
if not os.access(env_file, os.R_OK) and os.path.isfile(env_file):
rc = self.Spm.execute_package_phase(portage_atom, ebuild,
"setup",
work_dir = self.pkgdata['unpackdir'],
+1 -1
View File
@@ -46,7 +46,7 @@ class FileUpdates:
def remove_file(self, key):
self.scanfs(dcache = True)
source_file = etpConst['systemroot'] + self.scandata[key]['source']
if os.access(source_file, os.F_OK) and os.access(source_file, os.W_OK):
if os.path.isfile(source_file) and os.access(source_file, os.W_OK):
os.remove(source_file)
self.remove_from_cache(key)
+1 -1
View File
@@ -973,7 +973,7 @@ def const_remove_entropy_pid():
"""
pid = os.getpid()
pid_file = etpConst['pidfile']
if not os.access(pid_file, os.F_OK):
if not os.path.lexists(pid_file):
return True # not found, so removed
# open file
+4 -2
View File
@@ -704,7 +704,7 @@ class SystemSettings(Singleton):
@rtype: string
"""
hw_hash_file = self.__setting_files['hw_hash']
if os.access(hw_hash_file, os.R_OK | os.F_OK):
if os.access(hw_hash_file, os.R_OK) and os.path.isfile(hw_hash_file):
hash_f = open(hw_hash_file, "r")
hash_data = hash_f.readline().strip()
hash_f.close()
@@ -713,7 +713,9 @@ class SystemSettings(Singleton):
hash_file_dir = os.path.dirname(hw_hash_file)
hw_hash_exec = etpConst['etp_hw_hash_gen']
if os.access(hash_file_dir, os.W_OK) and \
os.access(hw_hash_exec, os.X_OK | os.F_OK | os.R_OK):
os.access(hw_hash_exec, os.X_OK | os.R_OK) and \
os.path.isfile(hw_hash_exec):
pipe = os.popen('{ ' + hw_hash_exec + '; } 2>&1', 'r')
hash_data = pipe.read().strip()
sts = pipe.close()
+3 -1
View File
@@ -7424,7 +7424,9 @@ class EntropyRepository:
myatomcounterpath = os.path.join(os.path.dirname(build_path),
counter_path)
if not os.access(myatomcounterpath, os.F_OK | os.R_OK):
if not (os.access(myatomcounterpath, os.R_OK) and \
os.path.isfile(myatomcounterpath)):
if verbose:
mytxt = "%s: %s: %s" % (
bold(_("ATTENTION")),
+2 -2
View File
@@ -1033,11 +1033,11 @@ class LogFile:
@type file_path: string
"""
if isinstance(file_path, basestring):
if not os.access(file_path, os.F_OK) and os.access(
if not os.path.isfile(file_path) and os.access(
os.path.dirname(file_path), os.W_OK):
self._logfile = open(file_path, "aw")
else:
if os.access(file_path, os.W_OK | os.F_OK):
if os.access(file_path, os.W_OK) and os.path.isfile(file_path):
self._logfile = open(file_path, "aw")
else:
self._logfile = open("/dev/null", "aw")
+3 -2
View File
@@ -593,7 +593,8 @@ class QAInterface:
# obviously, we're looking for another ELF object
my_real_exec_dir = os.path.dirname(real_exec_path)
mylib_guess = os.path.join(my_real_exec_dir, mylib)
if os.access(mylib_guess, os.R_OK | os.F_OK):
if os.access(mylib_guess, os.R_OK) and \
os.path.isfile(mylib_guess):
if self.entropyTools.is_elf_file(mylib_guess):
# we have found the missing library,
# which wasn't in LDPATH, booooo @ package
@@ -951,7 +952,7 @@ class QAInterface:
fd, tmp_path = tempfile.mkstemp()
extract_path = self.entropyTools.extract_edb(pkg_path, tmp_path)
if extract_path is None:
if os.access(tmp_path, os.F_OK):
if os.path.isfile(tmp_path):
os.remove(tmp_path)
os.close(fd)
return False # error!
+3 -1
View File
@@ -116,7 +116,9 @@ class SecurityInterface:
pass
const_setup_perms(etpConst['securitydir'], etpConst['entropygid'])
if os.access(self.old_download_package_checksum, os.F_OK | os.R_OK):
if os.access(self.old_download_package_checksum, os.R_OK) and \
os.path.isfile(self.old_download_package_checksum):
f_down = open(self.old_download_package_checksum)
try:
self.previous_checksum = f_down.readline().strip().split()[0]
+1 -1
View File
@@ -261,7 +261,7 @@ class ServerFatscopeSystemSettingsPlugin(SystemSettingsPlugin):
dbconn = self._helper.open_server_repository(
just_reading = True, repo = repoid)
if os.access(exp_fp, os.R_OK | os.F_OK):
if os.access(exp_fp, os.R_OK) and os.path.isfile(exp_fp):
pkgs = self.entropyTools.generic_file_content_parser(exp_fp)
if '*' in pkgs: # wildcard support
idpackages.add(-1)
+14 -5
View File
@@ -204,7 +204,7 @@ class Server:
break
down_path = os.path.join(tmp_dir, filename)
if success and os.access(down_path, os.F_OK):
if success and os.path.isfile(down_path):
down_f = open(down_path)
branch_data[branch] = down_f.read()
down_f.close()
@@ -782,7 +782,9 @@ class Server:
dlcount -= 1
crippled_uri = self.entropyTools.extract_ftp_host_from_uri(uri)
if os.access(revision_localtmppath, os.R_OK | os.F_OK):
if os.access(revision_localtmppath, os.R_OK) and \
os.path.isfile(revision_localtmppath):
f_rev = open(revision_localtmppath,"r")
try:
revision = int(f_rev.readline().strip())
@@ -801,6 +803,7 @@ class Server:
)
revision = 0
f_rev.close()
elif dlcount == 0:
self.Entropy.updateProgress(
"[repo:%s|%s] %s: %s" % (
@@ -814,6 +817,7 @@ class Server:
header = darkred(" !!! ")
)
revision = 0
else:
self.Entropy.updateProgress(
"[repo:%s|%s] %s: %s" % (
@@ -827,6 +831,7 @@ class Server:
header = darkred(" !!! ")
)
revision = 0
if os.path.isfile(revision_localtmppath):
os.remove(revision_localtmppath)
@@ -1488,7 +1493,7 @@ class Server:
def _create_metafiles_file(self, compressed_dest_path, file_list, repo):
found_file_list = [x for x in file_list if os.path.isfile(x) and \
os.access(x, os.F_OK) and os.access(x, os.R_OK)]
os.path.isfile(x) and os.access(x, os.R_OK)]
not_found_file_list = ["%s\n" % (os.path.basename(x),) for x in \
file_list if x not in found_file_list]
metafile_not_found_file = \
@@ -1737,8 +1742,10 @@ class Server:
copy_back = False
if not pretend:
try:
if os.access(backup_dbpath, os.R_OK | os.F_OK):
if os.access(backup_dbpath, os.R_OK) and \
os.path.isfile(backup_dbpath):
os.remove(backup_dbpath)
shutil.copy2(old_dbpath, backup_dbpath)
copy_back = True
except shutil.Error:
@@ -2047,7 +2054,9 @@ class Server:
if not mirrors_locked and db_locked:
# mirrors not locked remotely but only locally
mylock_file = self.get_database_lockfile(repo)
if os.access(mylock_file, os.W_OK | os.F_OK):
if os.access(mylock_file, os.W_OK) and \
os.path.isfile(mylock_file):
os.remove(mylock_file)
continue
@@ -145,7 +145,8 @@ class Server(SocketHost):
compressed_dbfile = etpConst[cmethod_data[2]]
compressed_dbpath = os.path.join(dbpath, compressed_dbfile)
if not os.access(compressed_dbpath, os.R_OK | os.F_OK | os.W_OK):
if not (os.access(compressed_dbpath, os.R_OK | os.W_OK) and \
os.path.isfile(compressed_dbpath)):
mytxt = darkred("%s: %s !!") % (
_("cannot unlock database, compressed file not found"),
compressed_dbpath,
@@ -264,7 +264,7 @@ class PortagePlugin(SpmPlugin):
if isinstance(ebuild_path, basestring):
clog_path = os.path.join(os.path.dirname(ebuild_path), "ChangeLog")
if os.access(clog_path, os.R_OK | os.F_OK):
if os.access(clog_path, os.R_OK) and os.path.isfile(clog_path):
with open(clog_path, "r") as clog_f:
return clog_f.read()
@@ -342,7 +342,8 @@ class PortagePlugin(SpmPlugin):
if security_property == "new":
checklist = []
if os.access(glsaconfig["CHECKFILE"], os.R_OK | os.F_OK):
if os.access(glsaconfig["CHECKFILE"], os.R_OK) and \
os.path.isfile(glsaconfig["CHECKFILE"]):
with open(glsaconfig["CHECKFILE"], "r") as check_f:
checklist.extend([x.strip() for x in check_f.readlines()])
glsalist = [x for x in completelist if x not in checklist]
@@ -571,7 +572,7 @@ class PortagePlugin(SpmPlugin):
dblnk.unlockdb()
if os.access(file_save_path, os.F_OK):
if os.path.isfile(file_save_path):
return file_save_path
raise SPMError("SPMError: Spm:generate_package %s: %s %s" % (
@@ -720,7 +721,7 @@ class PortagePlugin(SpmPlugin):
data['trigger'] = ""
trigger_file = os.path.join(etpConst['triggersdir'], data['category'],
data['name'], etpConst['triggername'])
if os.access(trigger_file, os.F_OK | os.R_OK):
if os.access(trigger_file, os.R_OK) and os.path.isfile(trigger_file):
with open(trigger_file,"rb") as trig_f:
data['trigger'] = trig_f.read()
@@ -1302,7 +1303,7 @@ class PortagePlugin(SpmPlugin):
### ACCEPT_LICENSE
for lic in licenses:
lic_path = os.path.join(portdir_lic, lic)
if not os.access(lic_path, os.F_OK):
if os.access(portdir_lic, os.W_OK | os.R_OK):
lic_f = open(lic_path, "w")
lic_f.close()
@@ -1453,7 +1454,7 @@ class PortagePlugin(SpmPlugin):
world_dir = os.path.dirname(world_file)
world_atoms = set()
if os.access(world_file, os.R_OK | os.F_OK):
if os.access(world_file, os.R_OK) and os.path.isfile(world_file):
with open(world_file, "r") as world_f:
world_atoms |= set((x.strip() for x in world_f.readlines() if \
x.strip()))
@@ -1499,8 +1500,6 @@ class PortagePlugin(SpmPlugin):
key = entropy.tools.dep_getkey(atom)
others_installed = self.match_installed_package(key, match_all = True)
if atom in others_installed:
others_installed.remove(atom)
# Support for tagged packages
slot = package_metadata['slot']
@@ -1532,9 +1531,14 @@ class PortagePlugin(SpmPlugin):
except OSError:
pass
if others_installed:
if isinstance(others_installed, (list, set, tuple,)):
for myatom in others_installed:
if myatom == atom:
# do not remove self
continue
myslot = self.get_installed_package_metadata(myatom, "SLOT")
if myslot != slot:
continue
@@ -1549,7 +1553,7 @@ class PortagePlugin(SpmPlugin):
# otherwise update Portage world file
world_file = self.get_user_installed_packages_file()
world_file_tmp = world_file + ".entropy.tmp"
if os.access(world_file, os.W_OK | os.F_OK):
if os.access(world_file, os.W_OK) and os.path.isfile(world_file):
new = open(world_file_tmp,"w")
old = open(world_file,"r")
@@ -1580,7 +1584,7 @@ class PortagePlugin(SpmPlugin):
atom = package_metadata['key'] + "-" + package_metadata['version']
myebuild = self.get_installed_package_build_script_path(atom)
if not os.access(myebuild, os.R_OK | os.F_OK):
if not (os.access(myebuild, os.R_OK) and os.path.isfile(myebuild)):
# cannot find ebuild ! ouch!
return 2
+1 -1
View File
@@ -1640,7 +1640,7 @@ def generic_file_content_parser(filepath):
@rtype:
"""
data = []
if os.access(filepath, os.R_OK | os.F_OK):
if os.access(filepath, os.R_OK) and os.path.isfile(filepath):
gen_f = open(filepath, "r")
content = gen_f.readlines()
gen_f.close()
+1 -1
View File
@@ -94,7 +94,7 @@ class AppletNoticeWindow(QWidget):
self.setWindowTitle(_("Application updates"))
# set window icon
if os.access(ICON_PATH, os.R_OK | os.F_OK):
if os.access(ICON_PATH, os.R_OK) and os.path.isfile(ICON_PATH):
self.__window_icon = QIcon(ICON_PATH)
self.setWindowIcon(self.__window_icon)
+1 -1
View File
@@ -27,7 +27,7 @@ def write_new_line(buf, data):
for path in args:
if not os.access(path, os.F_OK | os.R_OK | os.W_OK):
if not (os.path.isfile(path) and os.access(path, os.R_OK | os.W_OK)):
sys.stderr.write("unable to deal with %s\n" % (path,))
sys.stderr.flush()
continue
+2 -2
View File
@@ -461,11 +461,11 @@ class SulfurApplication(Controller, SulfurApplicationEventsMixin):
atoms_install.extend(sys.argv[sys.argv.index("--install")+1:])
packages_install = [x for x in packages_install if \
os.access(x, os.R_OK | os.F_OK)]
os.access(x, os.R_OK) and os.path.isfile(x)]
for arg in sys.argv:
if arg.endswith(etpConst['packagesext']) and \
os.access(arg, os.R_OK | os.F_OK):
os.access(arg, os.R_OK) and os.path.isfile(arg):
arg = os.path.realpath(arg)
packages_install.append(arg)
+1 -1
View File
@@ -173,7 +173,7 @@ class SulfurApplicationEventsMixin:
return True
"""
if not os.access(source, os.R_OK | os.W_OK | os.F_OK):
if not (os.access(source, os.R_OK | os.W_OK) os.path.isfile(source)):
return
source_f = open(source)
txt = source_f.read()