From 222753d9fbae1d5888018889b385609f42b1924e Mon Sep 17 00:00:00 2001 From: msweet Date: Wed, 28 Jan 2015 18:06:28 +0000 Subject: [PATCH] cupsd takes the slow path when loading job history even if the control files are older than the cache file () git-svn-id: svn+ssh://src.apple.com/svn/cups/cups.org/trunk@12435 a1ca3aef-8c08-0410-bb20-df032aa958be --- scheduler/job.c | 54 +++++++++++++++++++++++++++++++++++++------------ 1 file changed, 41 insertions(+), 13 deletions(-) diff --git a/scheduler/job.c b/scheduler/job.c index 7887c56a0..a2a6831a2 100644 --- a/scheduler/job.c +++ b/scheduler/job.c @@ -1531,9 +1531,10 @@ void cupsdLoadAllJobs(void) { char filename[1024]; /* Full filename of job.cache file */ - struct stat fileinfo, /* Information on job.cache file */ - dirinfo; /* Information on RequestRoot dir */ - + struct stat fileinfo; /* Information on job.cache file */ + cups_dir_t *dir; /* RequestRoot dir */ + cups_dentry_t *dent; /* Entry in RequestRoot */ + int load_cache = 1; /* Load the job.cache file? */ /* @@ -1557,36 +1558,63 @@ cupsdLoadAllJobs(void) if (stat(filename, &fileinfo)) { - fileinfo.st_mtime = 0; + /* + * No job.cache file... + */ + + load_cache = 0; if (errno != ENOENT) cupsdLogMessage(CUPSD_LOG_ERROR, "Unable to get file information for \"%s\" - %s", filename, strerror(errno)); } + else if ((dir = cupsDirOpen(RequestRoot)) == NULL) + { + /* + * No spool directory... + */ - if (stat(RequestRoot, &dirinfo)) + load_cache = 0; + } + else { - dirinfo.st_mtime = 0; + while ((dent = cupsDirRead(dir)) != NULL) + { + if (strlen(dent->filename) >= 6 && dent->filename[0] == 'c' && dent->fileinfo.st_mtime > fileinfo.st_mtime) + { + /* + * Job history file is newer than job.cache file... + */ - if (errno != ENOENT) - cupsdLogMessage(CUPSD_LOG_ERROR, - "Unable to get directory information for \"%s\" - %s", - RequestRoot, strerror(errno)); + load_cache = 0; + break; + } + } } /* * Load the most recent source for job data... */ - if (dirinfo.st_mtime > fileinfo.st_mtime) + if (load_cache) { + /* + * Load the job.cache file... + */ + + load_job_cache(filename); + } + else + { + /* + * Load the job history files... + */ + load_request_root(); load_next_job_id(filename); } - else - load_job_cache(filename); /* * Clean out old jobs as needed... -- 2.39.2