Codebase list debian-goodies / 09c21d4
If the file does not exist in the filesystem but it is a library do a broader search using the file's SONAME as a regexp. This helps associate deleted libraries with packages even when they have been replace with newer versions. Javier Fernandez-Sanguino 12 years ago
1 changed file(s) with 35 addition(s) and 18 deletion(s). Raw diff Collapse all Expand all
272272 processes.values())
273273 return toRestart
274274
275 # Tells if a file is part of a package
275 # Tells if a given file is part of a package
276276 # Returns:
277277 # - False - file does not exist in the system or cannot be found when querying the package database
278278 # - True - file is found in an operating system package
279279 def ispackagedFile (f):
280280 file_in_package = False
281 # First check if the file exists, do not call dpkg-query
282 # if the file simply does not exist in the file system
283 if os.path.exists(f):
281 file_regexp = False
282 if verbose:
283 print "Checking if file %s belongs to any package" % f
284 # First check if the file exists
285 if not os.path.exists(f):
286 if ( f.startswith('/lib/') or f.startswith('/usr/lib/') ) and re.compile("\.so[\d.]+$"):
287 # For libraries that do not exist then try to use a regular expression with the
288 # soname
289 f = re.compile("\.so[\d.]+$").sub(".so.*", f)
290 file_regexp = True
291 else:
292 # Do not call dpkg-query if the file simply does not exist in the file system
293 # just assume it does not belong to any package
294 return False
295
284296 # If it exists, run dpkg-query
285 dpkgQuery = ["dpkg-query", "--search", f]
286 dpkgProc = subprocess.Popen(dpkgQuery, stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
297 dpkgQuery = ["dpkg-query", "--search", f ]
298 dpkgProc = subprocess.Popen(dpkgQuery, stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
287299 env = lc_all_c_env, close_fds=True)
288 dpkgProc.wait()
289 if verbose:
290 print "Running:%s" % dpkgQuery
291 for line in dpkgProc.stdout.readlines():
292 line = line.strip()
293 if line.find('no path found matching pattern ' + f) > 0:
294 file_in_package = False
295 break
296 if line.endswith(f):
297 file_in_package = True
298 break
299
300 dpkgProc.wait()
301 if verbose:
302 print "Running:%s" % dpkgQuery
303 for line in dpkgProc.stdout.readlines():
304 line = line.strip()
305 if line.find('no path found matching pattern ' + f) > 0:
306 file_in_package = False
307 break
308 if line.endswith(f) or ( file_regexp and re.search(f, line)):
309 package = re.compile(":.*$").sub("",line)
310 file_in_package = True
311 break
312
313 if file_in_package and verbose:
314 print "YES: File belongs to package %s" % package
315 if not file_in_package and verbose:
316 print "NO: File does not belongs to any package"
300317 return file_in_package
301318
302319 # Tells if a file has to be considered a deleted file