Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
L
liblongpath-rsync
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
liblongpath
liblongpath-rsync
Commits
3eabe6aa
Commit
3eabe6aa
authored
Feb 03, 2008
by
Wayne Davison
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Dump delete_item()'s "replace" var to reduce recursive stack use.
parent
f2b7b64d
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
33 additions
and
18 deletions
+33
-18
generator.c
generator.c
+33
-18
No files found.
generator.c
View file @
3eabe6aa
...
@@ -117,6 +117,13 @@ static const char *solo_file = NULL;
...
@@ -117,6 +117,13 @@ static const char *solo_file = NULL;
#define DEL_OWNED_BY_US (1<<0)
/* file/dir has our uid */
#define DEL_OWNED_BY_US (1<<0)
/* file/dir has our uid */
#define DEL_RECURSE (1<<1)
/* if dir, delete all contents */
#define DEL_RECURSE (1<<1)
/* if dir, delete all contents */
#define DEL_DIR_IS_EMPTY (1<<2)
/* internal delete_FUNCTIONS use only */
#define DEL_DIR_IS_EMPTY (1<<2)
/* internal delete_FUNCTIONS use only */
#define DEL_FOR_FILE (1<<3)
/* making room for a replacement file */
#define DEL_FOR_DIR (1<<4)
/* making room for a replacement dir */
#define DEL_FOR_SYMLINK (1<<5)
/* making room for a replacement symlink */
#define DEL_FOR_DEVICE (1<<6)
/* making room for a replacement device */
#define DEL_FOR_SPECIAL (1<<7)
/* making room for a replacement special */
#define DEL_MAKE_ROOM (DEL_FOR_FILE|DEL_FOR_DIR|DEL_FOR_SYMLINK|DEL_FOR_DEVICE|DEL_FOR_SPECIAL)
enum
nonregtype
{
enum
nonregtype
{
TYPE_DIR
,
TYPE_SPECIAL
,
TYPE_DEVICE
,
TYPE_SYMLINK
TYPE_DIR
,
TYPE_SPECIAL
,
TYPE_DEVICE
,
TYPE_SYMLINK
...
@@ -129,7 +136,6 @@ enum delret {
...
@@ -129,7 +136,6 @@ enum delret {
/* Forward declaration for delete_item(). */
/* Forward declaration for delete_item(). */
static
enum
delret
delete_dir_contents
(
char
*
fname
,
int
flags
);
static
enum
delret
delete_dir_contents
(
char
*
fname
,
int
flags
);
static
int
is_backup_file
(
char
*
fn
)
static
int
is_backup_file
(
char
*
fn
)
{
{
int
k
=
strlen
(
fn
)
-
backup_suffix_len
;
int
k
=
strlen
(
fn
)
-
backup_suffix_len
;
...
@@ -142,7 +148,7 @@ static int is_backup_file(char *fn)
...
@@ -142,7 +148,7 @@ static int is_backup_file(char *fn)
* Note that fbuf must point to a MAXPATHLEN buffer if the mode indicates it's
* Note that fbuf must point to a MAXPATHLEN buffer if the mode indicates it's
* a directory! (The buffer is used for recursion, but returned unchanged.)
* a directory! (The buffer is used for recursion, but returned unchanged.)
*/
*/
static
enum
delret
delete_item
(
char
*
fbuf
,
int
mode
,
char
*
replace
,
int
flags
)
static
enum
delret
delete_item
(
char
*
fbuf
,
int
mode
,
int
flags
)
{
{
enum
delret
ret
;
enum
delret
ret
;
char
*
what
;
char
*
what
;
...
@@ -166,7 +172,7 @@ static enum delret delete_item(char *fbuf, int mode, char *replace, int flags)
...
@@ -166,7 +172,7 @@ static enum delret delete_item(char *fbuf, int mode, char *replace, int flags)
/* OK: try to delete the directory. */
/* OK: try to delete the directory. */
}
}
if
(
!
replace
&&
max_delete
>=
0
&&
++
deletion_count
>
max_delete
)
if
(
!
(
flags
&
DEL_MAKE_ROOM
)
&&
max_delete
>=
0
&&
++
deletion_count
>
max_delete
)
return
DR_AT_LIMIT
;
return
DR_AT_LIMIT
;
if
(
S_ISDIR
(
mode
))
{
if
(
S_ISDIR
(
mode
))
{
...
@@ -181,7 +187,7 @@ static enum delret delete_item(char *fbuf, int mode, char *replace, int flags)
...
@@ -181,7 +187,7 @@ static enum delret delete_item(char *fbuf, int mode, char *replace, int flags)
}
}
if
(
ok
)
{
if
(
ok
)
{
if
(
!
replace
)
if
(
!
(
flags
&
DEL_MAKE_ROOM
)
)
log_delete
(
fbuf
,
mode
);
log_delete
(
fbuf
,
mode
);
ret
=
DR_SUCCESS
;
ret
=
DR_SUCCESS
;
}
else
{
}
else
{
...
@@ -200,9 +206,18 @@ static enum delret delete_item(char *fbuf, int mode, char *replace, int flags)
...
@@ -200,9 +206,18 @@ static enum delret delete_item(char *fbuf, int mode, char *replace, int flags)
}
}
check_ret:
check_ret:
if
(
replace
&&
ret
!=
DR_SUCCESS
)
{
if
(
ret
!=
DR_SUCCESS
&&
flags
&
DEL_MAKE_ROOM
)
{
const
char
*
desc
;
switch
(
flags
&
DEL_MAKE_ROOM
)
{
case
DEL_FOR_FILE
:
desc
=
"regular file"
;
break
;
case
DEL_FOR_DIR
:
desc
=
"directory"
;
break
;
case
DEL_FOR_SYMLINK
:
desc
=
"symlink"
;
break
;
case
DEL_FOR_DEVICE
:
desc
=
"device file"
;
break
;
case
DEL_FOR_SPECIAL
:
desc
=
"special file"
;
break
;
default:
exit_cleanup
(
RERR_UNSUPPORTED
);
/* IMPOSSIBLE */
}
rprintf
(
FERROR_XFER
,
"could not make way for new %s: %s
\n
"
,
rprintf
(
FERROR_XFER
,
"could not make way for new %s: %s
\n
"
,
replace
,
fbuf
);
desc
,
fbuf
);
}
}
return
ret
;
return
ret
;
}
}
...
@@ -247,7 +262,7 @@ static enum delret delete_dir_contents(char *fname, int flags)
...
@@ -247,7 +262,7 @@ static enum delret delete_dir_contents(char *fname, int flags)
remainder
=
MAXPATHLEN
-
(
p
-
fname
);
remainder
=
MAXPATHLEN
-
(
p
-
fname
);
/* We do our own recursion, so make delete_item() non-recursive. */
/* We do our own recursion, so make delete_item() non-recursive. */
flags
=
(
flags
&
~
DEL_RECURSE
)
|
DEL_DIR_IS_EMPTY
;
flags
=
(
flags
&
~
(
DEL_RECURSE
|
DEL_MAKE_ROOM
)
)
|
DEL_DIR_IS_EMPTY
;
for
(
j
=
dirlist
->
used
;
j
--
;
)
{
for
(
j
=
dirlist
->
used
;
j
--
;
)
{
struct
file_struct
*
fp
=
dirlist
->
files
[
j
];
struct
file_struct
*
fp
=
dirlist
->
files
[
j
];
...
@@ -274,7 +289,7 @@ static enum delret delete_dir_contents(char *fname, int flags)
...
@@ -274,7 +289,7 @@ static enum delret delete_dir_contents(char *fname, int flags)
if
(
delete_dir_contents
(
fname
,
flags
|
DEL_RECURSE
)
!=
DR_SUCCESS
)
if
(
delete_dir_contents
(
fname
,
flags
|
DEL_RECURSE
)
!=
DR_SUCCESS
)
ret
=
DR_NOT_EMPTY
;
ret
=
DR_NOT_EMPTY
;
}
}
if
(
delete_item
(
fname
,
fp
->
mode
,
NULL
,
flags
)
!=
DR_SUCCESS
)
if
(
delete_item
(
fname
,
fp
->
mode
,
flags
)
!=
DR_SUCCESS
)
ret
=
DR_NOT_EMPTY
;
ret
=
DR_NOT_EMPTY
;
}
}
...
@@ -425,7 +440,7 @@ static void do_delayed_deletions(char *delbuf)
...
@@ -425,7 +440,7 @@ static void do_delayed_deletions(char *delbuf)
lseek
(
deldelay_fd
,
0
,
0
);
lseek
(
deldelay_fd
,
0
,
0
);
}
}
while
((
mode
=
read_delay_line
(
delbuf
,
&
own_flag
))
>=
0
)
while
((
mode
=
read_delay_line
(
delbuf
,
&
own_flag
))
>=
0
)
delete_item
(
delbuf
,
mode
,
NULL
,
own_flag
|
DEL_RECURSE
);
delete_item
(
delbuf
,
mode
,
own_flag
|
DEL_RECURSE
);
if
(
deldelay_fd
>=
0
)
if
(
deldelay_fd
>=
0
)
close
(
deldelay_fd
);
close
(
deldelay_fd
);
}
}
...
@@ -494,7 +509,7 @@ static void delete_in_dir(char *fbuf, struct file_struct *file, dev_t *fs_dev)
...
@@ -494,7 +509,7 @@ static void delete_in_dir(char *fbuf, struct file_struct *file, dev_t *fs_dev)
if
(
!
remember_delete
(
fp
,
delbuf
,
flags
))
if
(
!
remember_delete
(
fp
,
delbuf
,
flags
))
break
;
break
;
}
else
}
else
delete_item
(
delbuf
,
fp
->
mode
,
NULL
,
flags
);
delete_item
(
delbuf
,
fp
->
mode
,
flags
);
}
}
}
}
...
@@ -1315,7 +1330,7 @@ static void recv_generator(char *fname, struct file_struct *file, int ndx,
...
@@ -1315,7 +1330,7 @@ static void recv_generator(char *fname, struct file_struct *file, int ndx,
* full later (right before we handle its contents). */
* full later (right before we handle its contents). */
if
(
statret
==
0
if
(
statret
==
0
&&
(
S_ISDIR
(
sx
.
st
.
st_mode
)
&&
(
S_ISDIR
(
sx
.
st
.
st_mode
)
||
delete_item
(
fname
,
sx
.
st
.
st_mode
,
"directory"
,
del_opts
)
!=
0
))
||
delete_item
(
fname
,
sx
.
st
.
st_mode
,
del_opts
|
DEL_FOR_DIR
)
!=
0
))
goto
cleanup
;
/* Any errors get reported later. */
goto
cleanup
;
/* Any errors get reported later. */
if
(
do_mkdir
(
fname
,
file
->
mode
&
0700
)
==
0
)
if
(
do_mkdir
(
fname
,
file
->
mode
&
0700
)
==
0
)
file
->
flags
|=
FLAG_DIR_CREATED
;
file
->
flags
|=
FLAG_DIR_CREATED
;
...
@@ -1327,7 +1342,7 @@ static void recv_generator(char *fname, struct file_struct *file, int ndx,
...
@@ -1327,7 +1342,7 @@ static void recv_generator(char *fname, struct file_struct *file, int ndx,
* we need to delete it. If it doesn't exist, then
* we need to delete it. If it doesn't exist, then
* (perhaps recursively) create it. */
* (perhaps recursively) create it. */
if
(
statret
==
0
&&
!
S_ISDIR
(
sx
.
st
.
st_mode
))
{
if
(
statret
==
0
&&
!
S_ISDIR
(
sx
.
st
.
st_mode
))
{
if
(
delete_item
(
fname
,
sx
.
st
.
st_mode
,
"directory"
,
del_opts
)
!=
0
)
if
(
delete_item
(
fname
,
sx
.
st
.
st_mode
,
del_opts
|
DEL_FOR_DIR
)
!=
0
)
goto
skipping_dir_contents
;
goto
skipping_dir_contents
;
statret
=
-
1
;
statret
=
-
1
;
}
}
...
@@ -1456,7 +1471,7 @@ static void recv_generator(char *fname, struct file_struct *file, int ndx,
...
@@ -1456,7 +1471,7 @@ static void recv_generator(char *fname, struct file_struct *file, int ndx,
}
}
/* Not the right symlink (or not a symlink), so
/* Not the right symlink (or not a symlink), so
* delete it. */
* delete it. */
if
(
delete_item
(
fname
,
sx
.
st
.
st_mode
,
"symlink"
,
del_opts
)
!=
0
)
if
(
delete_item
(
fname
,
sx
.
st
.
st_mode
,
del_opts
|
DEL_FOR_SYMLINK
)
!=
0
)
goto
cleanup
;
goto
cleanup
;
}
else
if
(
basis_dir
[
0
]
!=
NULL
)
{
}
else
if
(
basis_dir
[
0
]
!=
NULL
)
{
int
j
=
try_dests_non
(
file
,
fname
,
ndx
,
fnamecmpbuf
,
&
sx
,
int
j
=
try_dests_non
(
file
,
fname
,
ndx
,
fnamecmpbuf
,
&
sx
,
...
@@ -1510,15 +1525,15 @@ static void recv_generator(char *fname, struct file_struct *file, int ndx,
...
@@ -1510,15 +1525,15 @@ static void recv_generator(char *fname, struct file_struct *file, int ndx,
uint32
*
devp
=
F_RDEV_P
(
file
);
uint32
*
devp
=
F_RDEV_P
(
file
);
dev_t
rdev
=
MAKEDEV
(
DEV_MAJOR
(
devp
),
DEV_MINOR
(
devp
));
dev_t
rdev
=
MAKEDEV
(
DEV_MAJOR
(
devp
),
DEV_MINOR
(
devp
));
if
(
statret
==
0
)
{
if
(
statret
==
0
)
{
char
*
t
;
int
del_for_flag
;
if
(
IS_DEVICE
(
file
->
mode
))
{
if
(
IS_DEVICE
(
file
->
mode
))
{
if
(
!
IS_DEVICE
(
sx
.
st
.
st_mode
))
if
(
!
IS_DEVICE
(
sx
.
st
.
st_mode
))
statret
=
-
1
;
statret
=
-
1
;
t
=
"device file"
;
del_for_flag
=
DEL_FOR_DEVICE
;
}
else
{
}
else
{
if
(
!
IS_SPECIAL
(
sx
.
st
.
st_mode
))
if
(
!
IS_SPECIAL
(
sx
.
st
.
st_mode
))
statret
=
-
1
;
statret
=
-
1
;
t
=
"special file"
;
del_for_flag
=
DEL_FOR_SPECIAL
;
}
}
if
(
statret
==
0
if
(
statret
==
0
&&
BITS_EQUAL
(
sx
.
st
.
st_mode
,
file
->
mode
,
_S_IFMT
)
&&
BITS_EQUAL
(
sx
.
st
.
st_mode
,
file
->
mode
,
_S_IFMT
)
...
@@ -1535,7 +1550,7 @@ static void recv_generator(char *fname, struct file_struct *file, int ndx,
...
@@ -1535,7 +1550,7 @@ static void recv_generator(char *fname, struct file_struct *file, int ndx,
goto
return_with_success
;
goto
return_with_success
;
goto
cleanup
;
goto
cleanup
;
}
}
if
(
delete_item
(
fname
,
sx
.
st
.
st_mode
,
t
,
del_opts
)
!=
0
)
if
(
delete_item
(
fname
,
sx
.
st
.
st_mode
,
del_opts
|
del_for_flag
)
!=
0
)
goto
cleanup
;
goto
cleanup
;
}
else
if
(
basis_dir
[
0
]
!=
NULL
)
{
}
else
if
(
basis_dir
[
0
]
!=
NULL
)
{
int
j
=
try_dests_non
(
file
,
fname
,
ndx
,
fnamecmpbuf
,
&
sx
,
int
j
=
try_dests_non
(
file
,
fname
,
ndx
,
fnamecmpbuf
,
&
sx
,
...
@@ -1626,7 +1641,7 @@ static void recv_generator(char *fname, struct file_struct *file, int ndx,
...
@@ -1626,7 +1641,7 @@ static void recv_generator(char *fname, struct file_struct *file, int ndx,
fnamecmp_type
=
FNAMECMP_FNAME
;
fnamecmp_type
=
FNAMECMP_FNAME
;
if
(
statret
==
0
&&
!
S_ISREG
(
sx
.
st
.
st_mode
))
{
if
(
statret
==
0
&&
!
S_ISREG
(
sx
.
st
.
st_mode
))
{
if
(
delete_item
(
fname
,
sx
.
st
.
st_mode
,
"regular file"
,
del_opts
)
!=
0
)
if
(
delete_item
(
fname
,
sx
.
st
.
st_mode
,
del_opts
|
DEL_FOR_FILE
)
!=
0
)
goto
cleanup
;
goto
cleanup
;
statret
=
-
1
;
statret
=
-
1
;
stat_errno
=
ENOENT
;
stat_errno
=
ENOENT
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment