From: Michael R Sweet Date: Wed, 2 Apr 2025 19:41:28 +0000 (-0400) Subject: Use cupsdCreateConfFile and friends when updating a PPD file (Issue #1109) X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=39684a11fa12261404777e431b2ad4e74c4e1e75;p=thirdparty%2Fcups.git Use cupsdCreateConfFile and friends when updating a PPD file (Issue #1109) --- diff --git a/scheduler/printers.c b/scheduler/printers.c index 9a4839a2f4..74595e5910 100644 --- a/scheduler/printers.c +++ b/scheduler/printers.c @@ -2804,8 +2804,7 @@ cupsdUpdatePrinterPPD( int i; /* Looping var */ cups_file_t *src, /* Original file */ *dst; /* New file */ - char srcfile[1024], /* Original filename */ - dstfile[1024], /* New filename */ + char filename[1024], /* PPD filename */ line[1024], /* Line from file */ keystring[41]; /* Keyword from line */ cups_option_t *keyword; /* Current keyword */ @@ -2814,34 +2813,21 @@ cupsdUpdatePrinterPPD( cupsdLogPrinter(p, CUPSD_LOG_INFO, "Updating keywords in PPD file."); /* - * Get the old and new PPD filenames... + * Get the base PPD filename... */ - snprintf(srcfile, sizeof(srcfile), "%s/ppd/%s.ppd.O", ServerRoot, p->name); - snprintf(dstfile, sizeof(srcfile), "%s/ppd/%s.ppd", ServerRoot, p->name); + snprintf(filename, sizeof(filename), "%s/ppd/%s.ppd", ServerRoot, p->name); /* - * Rename the old file and open the old and new... + * Open the old and new PPDs... */ - if (rename(dstfile, srcfile)) - { - cupsdLogPrinter(p, CUPSD_LOG_ERROR, "Unable to backup PPD file: %s", strerror(errno)); - return (0); - } - - if ((src = cupsFileOpen(srcfile, "r")) == NULL) - { - cupsdLogPrinter(p, CUPSD_LOG_ERROR, "Unable to open PPD file \"%s\": %s", srcfile, strerror(errno)); - rename(srcfile, dstfile); + if ((src = cupsdOpenConfFile(filename)) == NULL) return (0); - } - if ((dst = cupsFileOpen(dstfile, "w")) == NULL) + if ((dst = cupsdCreateConfFile(filename, ConfigFilePerm)) == NULL) { - cupsdLogPrinter(p, CUPSD_LOG_ERROR, "Unable to create PPD file \"%s\": %s", dstfile, strerror(errno)); cupsFileClose(src); - rename(srcfile, dstfile); return (0); } @@ -2851,10 +2837,9 @@ cupsdUpdatePrinterPPD( if (!cupsFileGets(src, line, sizeof(line))) { - cupsdLogPrinter(p, CUPSD_LOG_ERROR, "Unable to read PPD file \"%s\": %s", srcfile, strerror(errno)); + cupsdLogPrinter(p, CUPSD_LOG_ERROR, "Unable to read PPD file \"%s\": %s", filename, strerror(errno)); cupsFileClose(src); cupsFileClose(dst); - rename(srcfile, dstfile); return (0); } @@ -2892,7 +2877,7 @@ cupsdUpdatePrinterPPD( */ cupsFileClose(src); - cupsFileClose(dst); + cupsdCloseCreatedConfFile(dst, filename); return (1); }