MCPcopy Create free account
hub / github.com/OpenPrinting/cups / cupsdCleanFiles

Function cupsdCleanFiles

scheduler/file.c:31–81  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

29 */
30
31void
32cupsdCleanFiles(const char *path, /* I - Directory to clean */
33 const char *pattern) /* I - Filename pattern or NULL */
34{
35 cups_dir_t *dir; /* Directory */
36 cups_dentry_t *dent; /* Directory entry */
37 char filename[1024]; /* Filename */
38 struct stat fileinfo; /* File link information */
39 int status; /* Status from unlink/rmdir */
40
41
42 cupsdLogMessage(CUPSD_LOG_DEBUG,
43 "cupsdCleanFiles(path=\"%s\", pattern=\"%s\")", path,
44 pattern ? pattern : "(null)");
45
46 if ((dir = cupsDirOpen(path)) == NULL)
47 {
48 cupsdLogMessage(CUPSD_LOG_ERROR, "Unable to open directory \"%s\" - %s",
49 path, strerror(errno));
50 return;
51 }
52
53 cupsdLogMessage(CUPSD_LOG_INFO, "Cleaning out old files in \"%s\".", path);
54
55 while ((dent = cupsDirRead(dir)) != NULL)
56 {
57 if (pattern && fnmatch(pattern, dent->filename, 0))
58 continue;
59
60 snprintf(filename, sizeof(filename), "%s/%s", path, dent->filename);
61 if (lstat(filename, &fileinfo))
62 continue;
63
64 if (S_ISDIR(fileinfo.st_mode))
65 {
66 cupsdCleanFiles(filename, pattern);
67
68 status = rmdir(filename);
69 }
70 else
71 {
72 status = cupsdUnlinkOrRemoveFile(filename);
73 }
74
75 if (status)
76 cupsdLogMessage(CUPSD_LOG_ERROR, "Unable to remove \"%s\" - %s", filename,
77 strerror(errno));
78 }
79
80 cupsDirClose(dir);
81}
82
83
84/*

Callers 1

mainFunction · 0.85

Calls 5

cupsdLogMessageFunction · 0.85
cupsDirOpenFunction · 0.85
cupsDirReadFunction · 0.85
cupsdUnlinkOrRemoveFileFunction · 0.85
cupsDirCloseFunction · 0.85

Tested by

no test coverage detected