Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Synchronet
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Main
Synchronet
Commits
d661427e
Commit
d661427e
authored
3 years ago
by
Rob Swindell
Browse files
Options
Downloads
Patches
Plain Diff
delfiles() now removes files and directories, recursively
parent
dc5896a0
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/xpdev/dirwrap.c
+20
-4
20 additions, 4 deletions
src/xpdev/dirwrap.c
with
20 additions
and
4 deletions
src/xpdev/dirwrap.c
+
20
−
4
View file @
d661427e
...
...
@@ -732,16 +732,20 @@ int removecase(const char *path)
/****************************************************************************/
/* Deletes all files in dir 'path' that match file spec 'spec' */
/* If spec matches a sub-directory, it is traversed and removed recursively */
/* Optionally, keep the last so many files (sorted by name) */
/* Returns number of files deleted or negative on error */
/****************************************************************************/
long
delfiles
(
const
char
*
inpath
,
const
char
*
spec
,
size_t
keep
)
{
char
*
path
;
char
*
path
;
char
*
fpath
;
char
*
fname
;
char
lastch
;
size_t
i
;
ulong
files
=
0
;
long
errors
=
0
;
long
recursed
;
glob_t
g
;
size_t
inpath_len
=
strlen
(
inpath
);
int
flags
=
...
...
@@ -769,10 +773,22 @@ long delfiles(const char *inpath, const char *spec, size_t keep)
if
(
keep
>=
g
.
gl_pathc
)
return
0
;
for
(
i
=
0
;
i
<
g
.
gl_pathc
&&
files
<
g
.
gl_pathc
-
keep
;
i
++
)
{
if
(
isdir
(
g
.
gl_pathv
[
i
]))
fpath
=
g
.
gl_pathv
[
i
];
if
(
isdir
(
fpath
))
{
fname
=
getfname
(
fpath
);
if
(
strcmp
(
fname
,
"."
)
==
0
||
strcmp
(
fname
,
".."
)
==
0
)
continue
;
recursed
=
delfiles
(
fpath
,
spec
,
keep
);
if
(
recursed
>=
0
)
files
+=
recursed
;
else
errors
+=
recursed
;
if
(
rmdir
(
fpath
)
!=
0
)
errors
++
;
continue
;
(
void
)
CHMOD
(
g
.
gl_pathv
[
i
],
S_IWRITE
);
/* In case it's been marked RDONLY */
if
(
remove
(
g
.
gl_pathv
[
i
])
==
0
)
}
(
void
)
CHMOD
(
fpath
,
S_IWRITE
);
/* In case it's been marked RDONLY */
if
(
remove
(
fpath
)
==
0
)
files
++
;
else
errors
++
;
...
...
This diff is collapsed.
Click to expand it.
Rob Swindell
@rswindell
mentioned in commit
5e025ef3
·
3 months ago
mentioned in commit
5e025ef3
mentioned in commit 5e025ef3f92105834d4c71784852026e4a66ad75
Toggle commit list
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment