Skip to content

Commit

Permalink
Update state filename to current PAPPL standard, rename old state fil…
Browse files Browse the repository at this point in the history
…enames (Issue #129)
  • Loading branch information
michaelrsweet committed Feb 19, 2024
1 parent e2dfccf commit 648bc20
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 7 deletions.
2 changes: 1 addition & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ LPrint Change History
v1.3.2 - Month DD, YYYY
-----------------------

-
- Updated the default state file to match current PAPPL defaults (Issue #129)


v1.3.1 - February 9, 2024
Expand Down
39 changes: 33 additions & 6 deletions lprint.c
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,7 @@ system_cb(
*logfile, // Log file, if any
*spooldir, // Spool directory, if any
*system_name; // System name, if any
char oldfile[1024]; // Old configuration filename
pappl_loglevel_t loglevel; // Log level
int port = 0; // Port number, if any
pappl_soptions_t soptions = PAPPL_SOPTIONS_MULTI_QUEUE | PAPPL_SOPTIONS_WEB_INTERFACE | PAPPL_SOPTIONS_WEB_LOG | PAPPL_SOPTIONS_WEB_SECURITY;
Expand Down Expand Up @@ -554,27 +555,31 @@ system_cb(
if ((val = getenv("SNAP_DATA")) != NULL)
{
snprintf(lprint_spooldir, sizeof(lprint_spooldir), "%s/lprint.d", val);
snprintf(lprint_statefile, sizeof(lprint_statefile), "%s/lprint.conf", val);
snprintf(oldfile, sizeof(oldfile), "%s/lprint.conf", val);
snprintf(lprint_statefile, sizeof(lprint_statefile), "%s/lprint.state", val);

if (!spooldir)
spooldir = lprint_spooldir;
}
else if ((val = getenv("XDG_DATA_HOME")) != NULL)
{
snprintf(lprint_statefile, sizeof(lprint_statefile), "%s/.lprint.conf", val);
snprintf(oldfile, sizeof(oldfile), "%s/.lprint.conf", val);
snprintf(lprint_statefile, sizeof(lprint_statefile), "%s/lprint.state", val);
}
#ifdef _WIN32
else if ((val = getenv("USERPROFILE")) != NULL)
{
snprintf(lprint_spooldir, sizeof(lprint_spooldir), "%s/AppData/Local/lprint.d", val);
snprintf(lprint_statefile, sizeof(lprint_statefile), "%s/AppData/Local/lprint.ini", val);
snprintf(oldfile, sizeof(oldfile), "%s/AppData/Local/lprint.ini", val);
snprintf(lprint_statefile, sizeof(lprint_statefile), "%s/AppData/Local/lprint.state", val);

if (!spooldir)
spooldir = lprint_spooldir;
}
else
{
papplCopyString(lprint_statefile, "/lprint.ini", sizeof(lprint_statefile));
papplCopyString(oldfile, "/lprint.ini", sizeof(oldfile));
papplCopyString(lprint_statefile, "/lprint.state", sizeof(lprint_statefile));
}
#else
else if ((val = getenv("HOME")) != NULL)
Expand All @@ -586,15 +591,37 @@ system_cb(
if (!spooldir)
spooldir = lprint_spooldir;
# else
snprintf(lprint_statefile, sizeof(lprint_statefile), "%s/.lprint.conf", val);
snprintf(oldfile, sizeof(oldfile), "%s/.config", val);
if (access(oldfile, 0))
{
if (mkdir(oldfile, 0777))
{
perror(oldfile);
return (NULL);
}
}

snprintf(oldfile, sizeof(oldfile), "%s/.lprint.conf", val);
snprintf(lprint_statefile, sizeof(lprint_statefile), "%s/.config/lprint.state", val);
# endif // __APPLE__
}
else
{
papplCopyString(lprint_statefile, "/etc/lprint.conf", sizeof(lprint_statefile));
papplCopyString(oldfile, "/etc/lprint.conf", sizeof(oldfile));
# ifdef __APPLE__
papplCopyString(lprint_statefile, "/private/var/lib/lprint.state", sizeof(lprint_statefile));
# else
papplCopyString(lprint_statefile, "/var/lib/lprint.state", sizeof(lprint_statefile));
# endif // __APPLE__
}
#endif // _WIN32

if (!access(oldfile, 0) && access(lprint_statefile, 0))
{
// Move old state file to new name...
rename(oldfile, lprint_statefile);
}

if (spooldir && access(spooldir, 0))
{
if (mkdir(spooldir, 0777))
Expand Down

0 comments on commit 648bc20

Please sign in to comment.