Skip to content

Commit 39684a1

Browse files
committed
Use cupsdCreateConfFile and friends when updating a PPD file (Issue #1109)
1 parent f3ade9a commit 39684a1

1 file changed

Lines changed: 8 additions & 23 deletions

File tree

scheduler/printers.c

Lines changed: 8 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2804,8 +2804,7 @@ cupsdUpdatePrinterPPD(
28042804
int i; /* Looping var */
28052805
cups_file_t *src, /* Original file */
28062806
*dst; /* New file */
2807-
char srcfile[1024], /* Original filename */
2808-
dstfile[1024], /* New filename */
2807+
char filename[1024], /* PPD filename */
28092808
line[1024], /* Line from file */
28102809
keystring[41]; /* Keyword from line */
28112810
cups_option_t *keyword; /* Current keyword */
@@ -2814,34 +2813,21 @@ cupsdUpdatePrinterPPD(
28142813
cupsdLogPrinter(p, CUPSD_LOG_INFO, "Updating keywords in PPD file.");
28152814

28162815
/*
2817-
* Get the old and new PPD filenames...
2816+
* Get the base PPD filename...
28182817
*/
28192818

2820-
snprintf(srcfile, sizeof(srcfile), "%s/ppd/%s.ppd.O", ServerRoot, p->name);
2821-
snprintf(dstfile, sizeof(srcfile), "%s/ppd/%s.ppd", ServerRoot, p->name);
2819+
snprintf(filename, sizeof(filename), "%s/ppd/%s.ppd", ServerRoot, p->name);
28222820

28232821
/*
2824-
* Rename the old file and open the old and new...
2822+
* Open the old and new PPDs...
28252823
*/
28262824

2827-
if (rename(dstfile, srcfile))
2828-
{
2829-
cupsdLogPrinter(p, CUPSD_LOG_ERROR, "Unable to backup PPD file: %s", strerror(errno));
2830-
return (0);
2831-
}
2832-
2833-
if ((src = cupsFileOpen(srcfile, "r")) == NULL)
2834-
{
2835-
cupsdLogPrinter(p, CUPSD_LOG_ERROR, "Unable to open PPD file \"%s\": %s", srcfile, strerror(errno));
2836-
rename(srcfile, dstfile);
2825+
if ((src = cupsdOpenConfFile(filename)) == NULL)
28372826
return (0);
2838-
}
28392827

2840-
if ((dst = cupsFileOpen(dstfile, "w")) == NULL)
2828+
if ((dst = cupsdCreateConfFile(filename, ConfigFilePerm)) == NULL)
28412829
{
2842-
cupsdLogPrinter(p, CUPSD_LOG_ERROR, "Unable to create PPD file \"%s\": %s", dstfile, strerror(errno));
28432830
cupsFileClose(src);
2844-
rename(srcfile, dstfile);
28452831
return (0);
28462832
}
28472833

@@ -2851,10 +2837,9 @@ cupsdUpdatePrinterPPD(
28512837

28522838
if (!cupsFileGets(src, line, sizeof(line)))
28532839
{
2854-
cupsdLogPrinter(p, CUPSD_LOG_ERROR, "Unable to read PPD file \"%s\": %s", srcfile, strerror(errno));
2840+
cupsdLogPrinter(p, CUPSD_LOG_ERROR, "Unable to read PPD file \"%s\": %s", filename, strerror(errno));
28552841
cupsFileClose(src);
28562842
cupsFileClose(dst);
2857-
rename(srcfile, dstfile);
28582843
return (0);
28592844
}
28602845

@@ -2892,7 +2877,7 @@ cupsdUpdatePrinterPPD(
28922877
*/
28932878

28942879
cupsFileClose(src);
2895-
cupsFileClose(dst);
2880+
cupsdCloseCreatedConfFile(dst, filename);
28962881

28972882
return (1);
28982883
}

0 commit comments

Comments
 (0)