Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/coreutils/src/src/copy.c |
Source code | Switch to Preprocessed file |
Line | Source | Count | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | /* copy.c -- core functions for copying files and directories | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2 | Copyright (C) 1989-2018 Free Software Foundation, Inc. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4 | This program is free software: you can redistribute it and/or modify | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5 | it under the terms of the GNU General Public License as published by | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6 | the Free Software Foundation, either version 3 of the License, or | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7 | (at your option) any later version. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
8 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
9 | This program is distributed in the hope that it will be useful, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
12 | GNU General Public License for more details. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
13 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
14 | You should have received a copy of the GNU General Public License | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
15 | along with this program. If not, see <https://www.gnu.org/licenses/>. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
16 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
17 | /* Extracted from cp.c and librarified by Jim Meyering. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
18 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
19 | #include <config.h> | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
20 | #include <stdio.h> | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
21 | #include <assert.h> | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
22 | #include <sys/ioctl.h> | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
23 | #include <sys/types.h> | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
24 | #include <selinux/selinux.h> | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
25 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
26 | #if HAVE_HURD_H | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
27 | # include <hurd.h> | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
28 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
29 | #if HAVE_PRIV_H | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
30 | # include <priv.h> | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
31 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
32 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
33 | #include "system.h" | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
34 | #include "acl.h" | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
35 | #include "backupfile.h" | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
36 | #include "buffer-lcm.h" | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
37 | #include "canonicalize.h" | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
38 | #include "copy.h" | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
39 | #include "cp-hash.h" | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
40 | #include "extent-scan.h" | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
41 | #include "die.h" | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
42 | #include "error.h" | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
43 | #include "fadvise.h" | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
44 | #include "fcntl--.h" | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
45 | #include "fiemap.h" | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
46 | #include "file-set.h" | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
47 | #include "filemode.h" | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
48 | #include "filenamecat.h" | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
49 | #include "force-link.h" | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
50 | #include "full-write.h" | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
51 | #include "hash.h" | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
52 | #include "hash-triple.h" | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
53 | #include "ignore-value.h" | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
54 | #include "ioblksize.h" | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
55 | #include "quote.h" | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
56 | #include "renameat2.h" | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
57 | #include "root-uid.h" | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
58 | #include "same.h" | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
59 | #include "savedir.h" | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
60 | #include "stat-size.h" | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
61 | #include "stat-time.h" | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
62 | #include "utimecmp.h" | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
63 | #include "utimens.h" | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
64 | #include "write-any-file.h" | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
65 | #include "areadlink.h" | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
66 | #include "yesno.h" | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
67 | #include "selinux.h" | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
68 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
69 | #if USE_XATTR | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
70 | # include <attr/error_context.h> | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
71 | # include <attr/libattr.h> | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
72 | # include <stdarg.h> | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
73 | # include "verror.h" | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
74 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
75 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
76 | #if HAVE_LINUX_FALLOC_H | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
77 | # include <linux/falloc.h> | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
78 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
79 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
80 | /* See HAVE_FALLOCATE workaround when including this file. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
81 | #ifdef HAVE_LINUX_FS_H | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
82 | # include <linux/fs.h> | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
83 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
84 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
85 | #if !defined FICLONE && defined __linux__ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
86 | # define FICLONE _IOW (0x94, 9, int) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
87 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
88 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
89 | #ifndef HAVE_FCHOWN | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
90 | # define HAVE_FCHOWN false | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
91 | # define fchown(fd, uid, gid) (-1) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
92 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
93 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
94 | #ifndef HAVE_LCHOWN | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
95 | # define HAVE_LCHOWN false | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
96 | # define lchown(name, uid, gid) chown (name, uid, gid) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
97 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
98 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
99 | #ifndef HAVE_MKFIFO | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
100 | static int | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
101 | rpl_mkfifo (char const *file, mode_t mode) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
102 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
103 | errno = ENOTSUP; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
104 | return -1; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
105 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
106 | # define mkfifo rpl_mkfifo | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
107 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
108 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
109 | #ifndef USE_ACL | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
110 | # define USE_ACL 0 | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
111 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
112 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
113 | #define SAME_OWNER(A, B) ((A).st_uid == (B).st_uid) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
114 | #define SAME_GROUP(A, B) ((A).st_gid == (B).st_gid) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
115 | #define SAME_OWNER_AND_GROUP(A, B) (SAME_OWNER (A, B) && SAME_GROUP (A, B)) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
116 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
117 | /* LINK_FOLLOWS_SYMLINKS is tri-state; if it is -1, we don't know | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
118 | how link() behaves, so assume we can't hardlink symlinks in that case. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
119 | #if (defined HAVE_LINKAT && ! LINKAT_SYMLINK_NOTSUP) || ! LINK_FOLLOWS_SYMLINKS | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
120 | # define CAN_HARDLINK_SYMLINKS 1 | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
121 | #else | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
122 | # define CAN_HARDLINK_SYMLINKS 0 | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
123 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
124 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
125 | struct dir_list | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
126 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
127 | struct dir_list *parent; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
128 | ino_t ino; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
129 | dev_t dev; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
130 | }; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
131 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
132 | /* Initial size of the cp.dest_info hash table. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
133 | #define DEST_INFO_INITIAL_CAPACITY 61 | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
134 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
135 | static bool copy_internal (char const *src_name, char const *dst_name, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
136 | bool new_dst, struct stat const *parent, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
137 | struct dir_list *ancestors, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
138 | const struct cp_options *x, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
139 | bool command_line_arg, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
140 | bool *first_dir_created_per_command_line_arg, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
141 | bool *copy_into_self, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
142 | bool *rename_succeeded); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
143 | static bool owner_failure_ok (struct cp_options const *x); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
144 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
145 | /* Pointers to the file names: they're used in the diagnostic that is issued | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
146 | when we detect the user is trying to copy a directory into itself. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
147 | static char const *top_level_src_name; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
148 | static char const *top_level_dst_name; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
149 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
150 | /* Set the timestamp of symlink, FILE, to TIMESPEC. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
151 | If this system lacks support for that, simply return 0. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
152 | static inline int | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
153 | utimens_symlink (char const *file, struct timespec const *timespec) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
154 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
155 | int err = lutimens (file, timespec); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
156 | /* When configuring on a system with new headers and libraries, and | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
157 | running on one with a kernel that is old enough to lack the syscall, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
158 | utimensat fails with ENOSYS. Ignore that. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
159 | if (err && errno == ENOSYS)
| 0-3 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
160 | err = 0; never executed: err = 0; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
161 | return err; executed 3 times by 2 tests: return err; Executed by:
| 3 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
162 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
163 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
164 | /* Attempt to punch a hole to avoid any permanent | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
165 | speculative preallocation on file systems such as XFS. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
166 | Return values as per fallocate(2) except ENOSYS etc. are ignored. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
167 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
168 | static int | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
169 | punch_hole (int fd, off_t offset, off_t length) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
170 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
171 | int ret = 0; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
172 | /* +0 is to work around older <linux/fs.h> defining HAVE_FALLOCATE to empty. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
173 | #if HAVE_FALLOCATE + 0 | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
174 | # if defined FALLOC_FL_PUNCH_HOLE && defined FALLOC_FL_KEEP_SIZE | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
175 | ret = fallocate (fd, FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
176 | offset, length); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
177 | if (ret < 0 && (is_ENOTSUP (errno) || errno == ENOSYS))
| 0-1627 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
178 | ret = 0; never executed: ret = 0; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
179 | # endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
180 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
181 | return ret; executed 1627 times by 1 test: return ret; Executed by:
| 1627 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
182 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
183 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
184 | /* Create a hole at the end of a file, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
185 | avoiding preallocation if requested. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
186 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
187 | static bool | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
188 | create_hole (int fd, char const *name, bool punch_holes, off_t size) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
189 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
190 | off_t file_end = lseek (fd, size, SEEK_CUR); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
191 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
192 | if (file_end < 0)
| 0-1619 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
193 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
194 | error (0, errno, _("cannot lseek %s"), quoteaf (name)); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
195 | return false; never executed: return 0 ; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
196 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
197 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
198 | /* Some file systems (like XFS) preallocate when write extending a file. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
199 | I.e., a previous write() may have preallocated extra space | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
200 | that the seek above will not discard. A subsequent write() could | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
201 | then make this allocation permanent. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
202 | if (punch_holes && punch_hole (fd, file_end - size, size) < 0)
| 0-1618 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
203 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
204 | error (0, errno, _("error deallocating %s"), quoteaf (name)); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
205 | return false; never executed: return 0 ; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
206 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
207 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
208 | return true; executed 1619 times by 1 test: return 1 ; Executed by:
| 1619 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
209 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
210 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
211 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
212 | /* Copy the regular file open on SRC_FD/SRC_NAME to DST_FD/DST_NAME, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
213 | honoring the MAKE_HOLES setting and using the BUF_SIZE-byte buffer | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
214 | BUF for temporary storage. Copy no more than MAX_N_READ bytes. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
215 | Return true upon successful completion; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
216 | print a diagnostic and return false upon error. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
217 | Note that for best results, BUF should be "well"-aligned. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
218 | BUF must have sizeof(uintptr_t)-1 bytes of additional space | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
219 | beyond BUF[BUF_SIZE-1]. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
220 | Set *LAST_WRITE_MADE_HOLE to true if the final operation on | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
221 | DEST_FD introduced a hole. Set *TOTAL_N_READ to the number of | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
222 | bytes read. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
223 | static bool | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
224 | sparse_copy (int src_fd, int dest_fd, char *buf, size_t buf_size, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
225 | size_t hole_size, bool punch_holes, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
226 | char const *src_name, char const *dst_name, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
227 | uintmax_t max_n_read, off_t *total_n_read, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
228 | bool *last_write_made_hole) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
229 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
230 | *last_write_made_hole = false; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
231 | *total_n_read = 0; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
232 | bool make_hole = false; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
233 | off_t psize = 0; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
234 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
235 | while (max_n_read)
| 1394-7313 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
236 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
237 | ssize_t n_read = read (src_fd, buf, MIN (max_n_read, buf_size)); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
238 | if (n_read < 0)
| 0-7313 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
239 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
240 | if (errno == EINTR)
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
241 | continue; never executed: continue; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
242 | error (0, errno, _("error reading %s"), quoteaf (src_name)); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
243 | return false; never executed: return 0 ; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
244 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
245 | if (n_read == 0)
| 2918-4395 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
246 | break; executed 4395 times by 3 tests: break; Executed by:
| 4395 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
247 | max_n_read -= n_read; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
248 | *total_n_read += n_read; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
249 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
250 | /* Loop over the input buffer in chunks of hole_size. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
251 | size_t csize = hole_size ? hole_size : buf_size;
| 1444-1474 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
252 | char *cbuf = buf; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
253 | char *pbuf = buf; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
254 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
255 | while (n_read)
| 2918-9418 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
256 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
257 | bool prev_hole = make_hole; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
258 | csize = MIN (csize, n_read);
| 2918-6500 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
259 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
260 | if (hole_size && csize)
| 4-7974 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
261 | make_hole = is_nul (cbuf, csize); executed 7970 times by 1 test: make_hole = is_nul (cbuf, csize); Executed by:
| 7970 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
262 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
263 | bool transition = (make_hole != prev_hole) && psize;
| 18-8942 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
264 | bool last_chunk = (n_read == csize && ! make_hole) || ! csize;
| 4-6538 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
265 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
266 | if (transition || last_chunk)
| 458-8960 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
267 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
268 | if (! transition)
| 458-2876 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
269 | psize += csize; executed 2876 times by 3 tests: psize += csize; Executed by:
| 2876 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
270 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
271 | if (! prev_hole)
| 234-3100 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
272 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
273 | if (full_write (dest_fd, pbuf, psize) != psize)
| 0-3100 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
274 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
275 | error (0, errno, _("error writing %s"), | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
276 | quoteaf (dst_name)); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
277 | return false; never executed: return 0 ; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
278 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
279 | } executed 3100 times by 3 tests: end of block Executed by:
| 3100 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
280 | else | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
281 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
282 | if (! create_hole (dest_fd, dst_name, punch_holes, psize))
| 0-234 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
283 | return false; never executed: return 0 ; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
284 | } executed 234 times by 1 test: end of block Executed by:
| 234 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
285 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
286 | pbuf = cbuf; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
287 | psize = csize; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
288 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
289 | if (last_chunk)
| 454-2880 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
290 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
291 | if (! csize)
| 4-2876 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
292 | n_read = 0; /* Finished processing buffer. */ executed 4 times by 1 test: n_read = 0; Executed by:
| 4 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
293 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
294 | if (transition)
| 4-2876 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
295 | csize = 0; /* Loop again to deal with last chunk. */ executed 4 times by 1 test: csize = 0; Executed by:
| 4 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
296 | else | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
297 | psize = 0; /* Reset for next read loop. */ executed 2876 times by 3 tests: psize = 0; Executed by:
| 2876 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
298 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
299 | } executed 3334 times by 3 tests: end of block Executed by:
| 3334 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
300 | else /* Coalesce writes/seeks. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
301 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
302 | if (psize <= OFF_T_MAX - csize)
| 0-6084 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
303 | psize += csize; executed 6084 times by 1 test: psize += csize; Executed by:
| 6084 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
304 | else | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
305 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
306 | error (0, 0, _("overflow reading %s"), quoteaf (src_name)); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
307 | return false; never executed: return 0 ; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
308 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
309 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
310 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
311 | n_read -= csize; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
312 | cbuf += csize; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
313 | } executed 9418 times by 3 tests: end of block Executed by:
| 9418 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
314 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
315 | *last_write_made_hole = make_hole; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
316 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
317 | /* It's tempting to break early here upon a short read from | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
318 | a regular file. That would save the final read syscall | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
319 | for each file. Unfortunately that doesn't work for | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
320 | certain files in /proc or /sys with linux kernels. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
321 | } executed 2918 times by 3 tests: end of block Executed by:
| 2918 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
322 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
323 | /* Ensure a trailing hole is created, so that subsequent | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
324 | calls of sparse_copy() start at the correct offset. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
325 | if (make_hole && ! create_hole (dest_fd, dst_name, punch_holes, psize))
| 0-5781 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
326 | return false; never executed: return 0 ; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
327 | else | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
328 | return true; executed 5789 times by 3 tests: return 1 ; Executed by:
| 5789 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
329 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
330 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
331 | /* Perform the O(1) btrfs clone operation, if possible. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
332 | Upon success, return 0. Otherwise, return -1 and set errno. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
333 | static inline int | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
334 | clone_file (int dest_fd, int src_fd) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
335 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
336 | #ifdef FICLONE | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
337 | return ioctl (dest_fd, FICLONE, src_fd); executed 3923 times by 2 tests: return ioctl (dest_fd, (((1U) << (((0 +8)+8)+14)) | (((0x94)) << (0 +8)) | (((9)) << 0) | ((((sizeof(int)))) << ((0 +8)+8))) , src_fd); Executed by:
| 3923 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
338 | #else | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
339 | (void) dest_fd; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
340 | (void) src_fd; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
341 | errno = ENOTSUP; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
342 | return -1; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
343 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
344 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
345 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
346 | /* Write N_BYTES zero bytes to file descriptor FD. Return true if successful. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
347 | Upon write failure, set errno and return false. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
348 | static bool | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
349 | write_zeros (int fd, off_t n_bytes) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
350 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
351 | static char *zeros; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
352 | static size_t nz = IO_BUFSIZE; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
353 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
354 | /* Attempt to use a relatively large calloc'd source buffer for | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
355 | efficiency, but if that allocation fails, resort to a smaller | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
356 | statically allocated one. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
357 | if (zeros == NULL)
| 0-5 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
358 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
359 | static char fallback[1024]; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
360 | zeros = calloc (nz, 1); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
361 | if (zeros == NULL)
| 0-5 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
362 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
363 | zeros = fallback; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
364 | nz = sizeof fallback; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
365 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
366 | } executed 5 times by 1 test: end of block Executed by:
| 5 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
367 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
368 | while (n_bytes)
| 5-42 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
369 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
370 | size_t n = MIN (nz, n_bytes);
| 5-37 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
371 | if ((full_write (fd, zeros, n)) != n)
| 0-42 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
372 | return false; never executed: return 0 ; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
373 | n_bytes -= n; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
374 | } executed 42 times by 1 test: end of block Executed by:
| 42 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
375 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
376 | return true; executed 5 times by 1 test: return 1 ; Executed by:
| 5 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
377 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
378 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
379 | /* Perform an efficient extent copy, if possible. This avoids | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
380 | the overhead of detecting holes in hole-introducing/preserving | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
381 | copy, and thus makes copying sparse files much more efficient. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
382 | Upon a successful copy, return true. If the initial extent scan | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
383 | fails, set *NORMAL_COPY_REQUIRED to true and return false. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
384 | Upon any other failure, set *NORMAL_COPY_REQUIRED to false and | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
385 | return false. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
386 | static bool | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
387 | extent_copy (int src_fd, int dest_fd, char *buf, size_t buf_size, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
388 | size_t hole_size, off_t src_total_size, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
389 | enum Sparse_type sparse_mode, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
390 | char const *src_name, char const *dst_name, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
391 | bool *require_normal_copy) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
392 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
393 | struct extent_scan scan; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
394 | off_t last_ext_start = 0; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
395 | off_t last_ext_len = 0; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
396 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
397 | /* Keep track of the output position. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
398 | We may need this at the end, for a final ftruncate. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
399 | off_t dest_pos = 0; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
400 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
401 | extent_scan_init (src_fd, &scan); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
402 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
403 | *require_normal_copy = false; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
404 | bool wrote_hole_at_eof = true; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
405 | do | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
406 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
407 | bool ok = extent_scan_read (&scan); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
408 | if (! ok)
| 9-64 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
409 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
410 | if (scan.hit_final_extent)
| 4-5 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
411 | break; executed 4 times by 1 test: break; Executed by:
| 4 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
412 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
413 | if (scan.initial_scan_failed)
| 0-5 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
414 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
415 | *require_normal_copy = true; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
416 | return false; executed 5 times by 1 test: return 0 ; Executed by:
| 5 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
417 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
418 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
419 | error (0, errno, _("%s: failed to get extents info"), | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
420 | quotef (src_name)); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
421 | return false; never executed: return 0 ; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
422 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
423 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
424 | bool empty_extent = false; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
425 | for (unsigned int i = 0; i < scan.ei_count || empty_extent; i++)
| 0-1394 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
426 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
427 | off_t ext_start; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
428 | off_t ext_len; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
429 | off_t ext_hole_size; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
430 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
431 | if (i < scan.ei_count)
| 0-1394 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
432 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
433 | ext_start = scan.ext_info[i].ext_logical; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
434 | ext_len = scan.ext_info[i].ext_length; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
435 | } executed 1394 times by 1 test: end of block Executed by:
| 1394 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
436 | else /* empty extent at EOF. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
437 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
438 | i--; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
439 | ext_start = last_ext_start + scan.ext_info[i].ext_length; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
440 | ext_len = 0; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
441 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
442 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
443 | /* Truncate extent to EOF. Extents starting after EOF are | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
444 | treated as zero length extents starting right after EOF. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
445 | Generally this will trigger with an extent starting after | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
446 | src_total_size, and result in creating a hole or zeros until EOF. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
447 | Though in a file in which extents have changed since src_total_size | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
448 | was determined, we might have an extent spanning that size, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
449 | in which case we'll only copy data up to that size. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
450 | if (src_total_size < ext_start + ext_len)
| 23-1371 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
451 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
452 | if (src_total_size < ext_start)
| 3-20 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
453 | ext_start = src_total_size; executed 3 times by 1 test: ext_start = src_total_size; Executed by:
| 3 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
454 | ext_len = src_total_size - ext_start; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
455 | } executed 23 times by 1 test: end of block Executed by:
| 23 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
456 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
457 | ext_hole_size = ext_start - last_ext_start - last_ext_len; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
458 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
459 | wrote_hole_at_eof = false; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
460 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
461 | if (ext_hole_size)
| 15-1379 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
462 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
463 | if (lseek (src_fd, ext_start, SEEK_SET) < 0)
| 0-1379 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
464 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
465 | error (0, errno, _("cannot lseek %s"), quoteaf (src_name)); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
466 | fail: code before this statement never executed: fail: | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
467 | extent_scan_free (&scan); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
468 | return false; never executed: return 0 ; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
469 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
470 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
471 | if ((empty_extent && sparse_mode == SPARSE_ALWAYS)
| 0-1379 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
472 | || (!empty_extent && sparse_mode != SPARSE_NEVER))
| 0-1379 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
473 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
474 | if (! create_hole (dest_fd, dst_name,
| 0-1377 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
475 | sparse_mode == SPARSE_ALWAYS,
| 0-1377 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
476 | ext_hole_size))
| 0-1377 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
477 | goto fail; never executed: goto fail; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
478 | wrote_hole_at_eof = true; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
479 | } executed 1377 times by 1 test: end of block Executed by:
| 1377 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
480 | else | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
481 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
482 | /* When not inducing holes and when there is a hole between | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
483 | the end of the previous extent and the beginning of the | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
484 | current one, write zeros to the destination file. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
485 | off_t nzeros = ext_hole_size; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
486 | if (empty_extent)
| 0-2 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
487 | nzeros = MIN (src_total_size - dest_pos, ext_hole_size); never executed: nzeros = ((( src_total_size - dest_pos )<( ext_hole_size ))?( src_total_size - dest_pos ):( ext_hole_size )) ;
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
488 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
489 | if (! write_zeros (dest_fd, nzeros))
| 0-2 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
490 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
491 | error (0, errno, _("%s: write failed"), | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
492 | quotef (dst_name)); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
493 | goto fail; never executed: goto fail; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
494 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
495 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
496 | dest_pos = MIN (src_total_size, ext_start);
| 0-2 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
497 | } executed 2 times by 1 test: end of block Executed by:
| 2 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
498 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
499 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
500 | last_ext_start = ext_start; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
501 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
502 | /* Treat an unwritten but allocated extent much like a hole. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
503 | I.e., don't read, but don't convert to a hole in the destination, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
504 | unless SPARSE_ALWAYS. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
505 | /* For now, do not treat FIEMAP_EXTENT_UNWRITTEN specially, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
506 | because that (in combination with no sync) would lead to data | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
507 | loss at least on XFS and ext4 when using 2.6.39-rc3 kernels. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
508 | if (0 && (scan.ext_info[i].ext_flags & FIEMAP_EXTENT_UNWRITTEN)) dead code: (scan.ext_info[i].ext_flags & 0x00000800) dead code: { empty_extent = 1 ; last_ext_len = 0; if (ext_len == 0) empty_extent = 0 ; } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
509 | { dead code: { empty_extent = 1 ; last_ext_len = 0; if (ext_len == 0) empty_extent = 0 ; } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
510 | empty_extent = true; dead code: { empty_extent = 1 ; last_ext_len = 0; if (ext_len == 0) empty_extent = 0 ; } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
511 | last_ext_len = 0; dead code: { empty_extent = 1 ; last_ext_len = 0; if (ext_len == 0) empty_extent = 0 ; } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
512 | if (ext_len == 0) /* The last extent is empty and processed. */ dead code: { empty_extent = 1 ; last_ext_len = 0; if (ext_len == 0) empty_extent = 0 ; } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
513 | empty_extent = false; dead code: { empty_extent = 1 ; last_ext_len = 0; if (ext_len == 0) empty_extent = 0 ; } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
514 | } dead code: { empty_extent = 1 ; last_ext_len = 0; if (ext_len == 0) empty_extent = 0 ; } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
515 | else | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
516 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
517 | off_t n_read; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
518 | empty_extent = false; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
519 | last_ext_len = ext_len; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
520 | bool read_hole; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
521 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
522 | if ( ! sparse_copy (src_fd, dest_fd, buf, buf_size,
| 0-1394 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
523 | sparse_mode == SPARSE_ALWAYS ? hole_size: 0,
| 0-1394 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
524 | true, src_name, dst_name, ext_len, &n_read,
| 0-1394 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
525 | &read_hole))
| 0-1394 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
526 | goto fail; never executed: goto fail; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
527 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
528 | dest_pos = ext_start + n_read; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
529 | if (n_read)
| 3-1391 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
530 | wrote_hole_at_eof = read_hole; executed 1391 times by 1 test: wrote_hole_at_eof = read_hole; Executed by:
| 1391 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
531 | } executed 1394 times by 1 test: end of block Executed by:
| 1394 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
532 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
533 | /* If the file ends with unwritten extents not accounted for in the | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
534 | size, then skip processing them, and the associated redundant | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
535 | read() calls which will always return 0. We will need to | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
536 | remove this when we add fallocate() so that we can maintain | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
537 | extents beyond the apparent size. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
538 | if (dest_pos == src_total_size)
| 46-1348 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
539 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
540 | scan.hit_final_extent = true; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
541 | break; executed 46 times by 1 test: break; Executed by:
| 46 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
542 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
543 | } executed 1348 times by 1 test: end of block Executed by:
| 1348 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
544 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
545 | /* Release the space allocated to scan->ext_info. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
546 | extent_scan_free (&scan); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
547 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
548 | } executed 64 times by 1 test: end of block Executed by:
| 64 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
549 | while (! scan.hit_final_extent);
| 8-56 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
550 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
551 | /* When the source file ends with a hole, we have to do a little more work, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
552 | since the above copied only up to and including the final extent. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
553 | In order to complete the copy, we may have to insert a hole or write | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
554 | zeros in the destination corresponding to the source file's hole-at-EOF. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
555 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
556 | In addition, if the final extent was a block of zeros at EOF and we've | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
557 | just converted them to a hole in the destination, we must call ftruncate | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
558 | here in order to record the proper length in the destination. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
559 | if ((dest_pos < src_total_size || wrote_hole_at_eof)
| 2-46 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
560 | && (sparse_mode != SPARSE_NEVER
| 0-16 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
561 | ? ftruncate (dest_fd, src_total_size)
| 0-16 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
562 | : ! write_zeros (dest_fd, src_total_size - dest_pos)))
| 0-16 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
563 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
564 | error (0, errno, _("failed to extend %s"), quoteaf (dst_name)); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
565 | return false; never executed: return 0 ; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
566 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
567 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
568 | if (sparse_mode == SPARSE_ALWAYS && dest_pos < src_total_size
| 8-52 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
569 | && punch_hole (dest_fd, dest_pos, src_total_size - dest_pos) < 0)
| 0-9 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
570 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
571 | error (0, errno, _("error deallocating %s"), quoteaf (dst_name)); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
572 | return false; never executed: return 0 ; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
573 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
574 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
575 | return true; executed 60 times by 1 test: return 1 ; Executed by:
| 60 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
576 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
577 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
578 | /* FIXME: describe */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
579 | /* FIXME: rewrite this to use a hash table so we avoid the quadratic | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
580 | performance hit that's probably noticeable only on trees deeper | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
581 | than a few hundred levels. See use of active_dir_map in remove.c */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
582 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
583 | static bool _GL_ATTRIBUTE_PURE | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
584 | is_ancestor (const struct stat *sb, const struct dir_list *ancestors) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
585 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
586 | while (ancestors != 0)
| 33971-50028 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
587 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
588 | if (ancestors->ino == sb->st_ino && ancestors->dev == sb->st_dev)
| 0-50028 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
589 | return true; never executed: return 1 ; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
590 | ancestors = ancestors->parent; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
591 | } executed 50028 times by 2 tests: end of block Executed by:
| 50028 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
592 | return false; executed 33971 times by 2 tests: return 0 ; Executed by:
| 33971 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
593 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
594 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
595 | static bool | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
596 | errno_unsupported (int err) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
597 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
598 | return err == ENOTSUP || err == ENODATA; never executed: return err == 95 || err == 61 ; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
599 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
600 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
601 | #if USE_XATTR | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
602 | static void | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
603 | copy_attr_error (struct error_context *ctx _GL_UNUSED, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
604 | char const *fmt, ...) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
605 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
606 | if (!errno_unsupported (errno)) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
607 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
608 | int err = errno; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
609 | va_list ap; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
610 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
611 | /* use verror module to print error message */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
612 | va_start (ap, fmt); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
613 | verror (0, err, fmt, ap); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
614 | va_end (ap); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
615 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
616 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
617 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
618 | static void | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
619 | copy_attr_allerror (struct error_context *ctx _GL_UNUSED, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
620 | char const *fmt, ...) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
621 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
622 | int err = errno; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
623 | va_list ap; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
624 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
625 | /* use verror module to print error message */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
626 | va_start (ap, fmt); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
627 | verror (0, err, fmt, ap); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
628 | va_end (ap); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
629 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
630 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
631 | static char const * | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
632 | copy_attr_quote (struct error_context *ctx _GL_UNUSED, char const *str) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
633 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
634 | return quoteaf (str); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
635 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
636 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
637 | static void | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
638 | copy_attr_free (struct error_context *ctx _GL_UNUSED, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
639 | char const *str _GL_UNUSED) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
640 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
641 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
642 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
643 | /* Exclude SELinux extended attributes that are otherwise handled, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
644 | and are problematic to copy again. Also honor attributes | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
645 | configured for exclusion in /etc/xattr.conf. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
646 | FIXME: Should we handle POSIX ACLs similarly? | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
647 | Return zero to skip. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
648 | static int | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
649 | check_selinux_attr (const char *name, struct error_context *ctx) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
650 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
651 | return STRNCMP_LIT (name, "security.selinux") | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
652 | && attr_copy_check_permissions (name, ctx); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
653 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
654 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
655 | /* If positive SRC_FD and DST_FD descriptors are passed, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
656 | then copy by fd, otherwise copy by name. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
657 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
658 | static bool | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
659 | copy_attr (char const *src_path, int src_fd, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
660 | char const *dst_path, int dst_fd, struct cp_options const *x) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
661 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
662 | int ret; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
663 | bool all_errors = (!x->data_copy_required || x->require_preserve_xattr); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
664 | bool some_errors = (!all_errors && !x->reduce_diagnostics); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
665 | bool selinux_done = (x->preserve_security_context || x->set_security_context); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
666 | struct error_context ctx = | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
667 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
668 | .error = all_errors ? copy_attr_allerror : copy_attr_error, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
669 | .quote = copy_attr_quote, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
670 | .quote_free = copy_attr_free | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
671 | }; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
672 | if (0 <= src_fd && 0 <= dst_fd) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
673 | ret = attr_copy_fd (src_path, src_fd, dst_path, dst_fd, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
674 | selinux_done ? check_selinux_attr : NULL, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
675 | (all_errors || some_errors ? &ctx : NULL)); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
676 | else | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
677 | ret = attr_copy_file (src_path, dst_path, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
678 | selinux_done ? check_selinux_attr : NULL, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
679 | (all_errors || some_errors ? &ctx : NULL)); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
680 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
681 | return ret == 0; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
682 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
683 | #else /* USE_XATTR */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
684 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
685 | static bool | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
686 | copy_attr (char const *src_path _GL_UNUSED, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
687 | int src_fd _GL_UNUSED, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
688 | char const *dst_path _GL_UNUSED, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
689 | int dst_fd _GL_UNUSED, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
690 | struct cp_options const *x _GL_UNUSED) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
691 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
692 | return true; executed 37858 times by 2 tests: return 1 ; Executed by:
| 37858 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
693 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
694 | #endif /* USE_XATTR */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
695 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
696 | /* Read the contents of the directory SRC_NAME_IN, and recursively | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
697 | copy the contents to DST_NAME_IN. NEW_DST is true if | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
698 | DST_NAME_IN is a directory that was created previously in the | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
699 | recursion. SRC_SB and ANCESTORS describe SRC_NAME_IN. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
700 | Set *COPY_INTO_SELF if SRC_NAME_IN is a parent of | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
701 | (or the same as) DST_NAME_IN; otherwise, clear it. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
702 | Propagate *FIRST_DIR_CREATED_PER_COMMAND_LINE_ARG from | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
703 | caller to each invocation of copy_internal. Be careful to | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
704 | pass the address of a temporary, and to update | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
705 | *FIRST_DIR_CREATED_PER_COMMAND_LINE_ARG only upon completion. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
706 | Return true if successful. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
707 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
708 | static bool | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
709 | copy_dir (char const *src_name_in, char const *dst_name_in, bool new_dst, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
710 | const struct stat *src_sb, struct dir_list *ancestors, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
711 | const struct cp_options *x, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
712 | bool *first_dir_created_per_command_line_arg, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
713 | bool *copy_into_self) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
714 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
715 | char *name_space; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
716 | char *namep; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
717 | struct cp_options non_command_line_options = *x; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
718 | bool ok = true; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
719 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
720 | name_space = savedir (src_name_in, SAVEDIR_SORT_FASTREAD); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
721 | if (name_space == NULL)
| 0-33971 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
722 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
723 | /* This diagnostic is a bit vague because savedir can fail in | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
724 | several different ways. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
725 | error (0, errno, _("cannot access %s"), quoteaf (src_name_in)); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
726 | return false; never executed: return 0 ; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
727 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
728 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
729 | /* For cp's -H option, dereference command line arguments, but do not | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
730 | dereference symlinks that are found via recursive traversal. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
731 | if (x->dereference == DEREF_COMMAND_LINE_ARGUMENTS)
| 2-33969 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
732 | non_command_line_options.dereference = DEREF_NEVER; executed 2 times by 1 test: non_command_line_options.dereference = DEREF_NEVER; Executed by:
| 2 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
733 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
734 | bool new_first_dir_created = false; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
735 | namep = name_space; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
736 | while (*namep != '\0')
| 33960-63958 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
737 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
738 | bool local_copy_into_self; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
739 | char *src_name = file_name_concat (src_name_in, namep, NULL); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
740 | char *dst_name = file_name_concat (dst_name_in, namep, NULL); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
741 | bool first_dir_created = *first_dir_created_per_command_line_arg; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
742 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
743 | ok &= copy_internal (src_name, dst_name, new_dst, src_sb, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
744 | ancestors, &non_command_line_options, false, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
745 | &first_dir_created, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
746 | &local_copy_into_self, NULL); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
747 | *copy_into_self |= local_copy_into_self; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
748 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
749 | free (dst_name); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
750 | free (src_name); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
751 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
752 | /* If we're copying into self, there's no point in continuing, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
753 | and in fact, that would even infloop, now that we record only | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
754 | the first created directory per command line argument. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
755 | if (local_copy_into_self)
| 11-63947 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
756 | break; executed 11 times by 1 test: break; Executed by:
| 11 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
757 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
758 | new_first_dir_created |= first_dir_created; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
759 | namep += strlen (namep) + 1; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
760 | } executed 63947 times by 2 tests: end of block Executed by:
| 63947 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
761 | free (name_space); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
762 | *first_dir_created_per_command_line_arg = new_first_dir_created; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
763 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
764 | return ok; executed 33971 times by 2 tests: return ok; Executed by:
| 33971 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
765 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
766 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
767 | /* Set the owner and owning group of DEST_DESC to the st_uid and | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
768 | st_gid fields of SRC_SB. If DEST_DESC is undefined (-1), set | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
769 | the owner and owning group of DST_NAME instead; for | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
770 | safety prefer lchown if the system supports it since no | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
771 | symbolic links should be involved. DEST_DESC must | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
772 | refer to the same file as DEST_NAME if defined. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
773 | Upon failure to set both UID and GID, try to set only the GID. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
774 | NEW_DST is true if the file was newly created; otherwise, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
775 | DST_SB is the status of the destination. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
776 | Return 1 if the initial syscall succeeds, 0 if it fails but it's OK | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
777 | not to preserve ownership, -1 otherwise. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
778 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
779 | static int | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
780 | set_owner (const struct cp_options *x, char const *dst_name, int dest_desc, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
781 | struct stat const *src_sb, bool new_dst, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
782 | struct stat const *dst_sb) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
783 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
784 | uid_t uid = src_sb->st_uid; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
785 | gid_t gid = src_sb->st_gid; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
786 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
787 | /* Naively changing the ownership of an already-existing file before | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
788 | changing its permissions would create a window of vulnerability if | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
789 | the file's old permissions are too generous for the new owner and | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
790 | group. Avoid the window by first changing to a restrictive | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
791 | temporary mode if necessary. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
792 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
793 | if (!new_dst && (x->preserve_mode || x->move_mode || x->set_mode))
| 0-33933 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
794 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
795 | mode_t old_mode = dst_sb->st_mode; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
796 | mode_t new_mode = | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
797 | (x->preserve_mode || x->move_mode ? src_sb->st_mode : x->mode);
| 0-1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
798 | mode_t restrictive_temp_mode = old_mode & new_mode & S_IRWXU; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
799 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
800 | if ((USE_ACL | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
801 | || (old_mode & CHMOD_MODE_BITS
| 0-1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
802 | & (~new_mode | S_ISUID | S_ISGID | S_ISVTX)))
| 0-1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
803 | && qset_acl (dst_name, dest_desc, restrictive_temp_mode) != 0)
| 0-1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
804 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
805 | if (! owner_failure_ok (x))
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
806 | error (0, errno, _("clearing permissions for %s"), never executed: error (0, (*__errno_location ()) , dcgettext (((void *)0), "clearing permissions for %s" , 5) , quotearg_style (shell_escape_always_quoting_style, dst_name)); | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
807 | quoteaf (dst_name)); never executed: error (0, (*__errno_location ()) , dcgettext (((void *)0), "clearing permissions for %s" , 5) , quotearg_style (shell_escape_always_quoting_style, dst_name)); | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
808 | return -x->require_preserve; never executed: return -x->require_preserve; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
809 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
810 | } executed 1 time by 1 test: end of block Executed by:
| 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
811 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
812 | if (HAVE_FCHOWN && dest_desc != -1)
| 1-33933 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
813 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
814 | if (fchown (dest_desc, uid, gid) == 0)
| 0-1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
815 | return 1; executed 1 time by 1 test: return 1; Executed by:
| 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
816 | if (errno == EPERM || errno == EINVAL)
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
817 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
818 | /* We've failed to set *both*. Now, try to set just the group | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
819 | ID, but ignore any failure here, and don't change errno. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
820 | int saved_errno = errno; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
821 | ignore_value (fchown (dest_desc, -1, gid)); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
822 | errno = saved_errno; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
823 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
824 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
825 | else | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
826 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
827 | if (lchown (dst_name, uid, gid) == 0)
| 0-33933 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
828 | return 1; executed 33933 times by 2 tests: return 1; Executed by:
| 33933 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
829 | if (errno == EPERM || errno == EINVAL)
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
830 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
831 | /* We've failed to set *both*. Now, try to set just the group | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
832 | ID, but ignore any failure here, and don't change errno. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
833 | int saved_errno = errno; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
834 | ignore_value (lchown (dst_name, -1, gid)); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
835 | errno = saved_errno; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
836 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
837 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
838 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
839 | if (! chown_failure_ok (x))
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
840 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
841 | error (0, errno, _("failed to preserve ownership for %s"), | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
842 | quoteaf (dst_name)); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
843 | if (x->require_preserve)
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
844 | return -1; never executed: return -1; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
845 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
846 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
847 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
848 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
849 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
850 | /* Set the st_author field of DEST_DESC to the st_author field of | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
851 | SRC_SB. If DEST_DESC is undefined (-1), set the st_author field | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
852 | of DST_NAME instead. DEST_DESC must refer to the same file as | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
853 | DEST_NAME if defined. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
854 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
855 | static void | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
856 | set_author (const char *dst_name, int dest_desc, const struct stat *src_sb) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
857 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
858 | #if HAVE_STRUCT_STAT_ST_AUTHOR | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
859 | /* FIXME: Modify the following code so that it does not | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
860 | follow symbolic links. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
861 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
862 | /* Preserve the st_author field. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
863 | file_t file = (dest_desc < 0 | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
864 | ? file_name_lookup (dst_name, 0, 0) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
865 | : getdport (dest_desc)); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
866 | if (file == MACH_PORT_NULL) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
867 | error (0, errno, _("failed to lookup file %s"), quoteaf (dst_name)); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
868 | else | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
869 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
870 | error_t err = file_chauthor (file, src_sb->st_author); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
871 | if (err) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
872 | error (0, err, _("failed to preserve authorship for %s"), | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
873 | quoteaf (dst_name)); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
874 | mach_port_deallocate (mach_task_self (), file); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
875 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
876 | #else | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
877 | (void) dst_name; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
878 | (void) dest_desc; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
879 | (void) src_sb; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
880 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
881 | } executed 38433 times by 3 tests: end of block Executed by:
| 38433 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
882 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
883 | /* Set the default security context for the process. New files will | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
884 | have this security context set. Also existing files can have their | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
885 | context adjusted based on this process context, by | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
886 | set_file_security_ctx() called with PROCESS_LOCAL=true. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
887 | This should be called before files are created so there is no race | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
888 | where a file may be present without an appropriate security context. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
889 | Based on CP_OPTIONS, diagnose warnings and fail when appropriate. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
890 | Return FALSE on failure, TRUE on success. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
891 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
892 | bool | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
893 | set_process_security_ctx (char const *src_name, char const *dst_name, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
894 | mode_t mode, bool new_dst, const struct cp_options *x) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
895 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
896 | if (x->preserve_security_context)
| 0-68505 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
897 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
898 | /* Set the default context for the process to match the source. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
899 | bool all_errors = !x->data_copy_required || x->require_preserve_context;
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
900 | bool some_errors = !all_errors && !x->reduce_diagnostics;
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
901 | char *con; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
902 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
903 | if (0 <= lgetfilecon (src_name, &con))
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
904 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
905 | if (setfscreatecon (con) < 0)
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
906 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
907 | if (all_errors || (some_errors && !errno_unsupported (errno)))
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
908 | error (0, errno, never executed: error (0, (*__errno_location ()) , dcgettext (((void *)0), "failed to set default file creation context to %s" , 5) , quote (con)); | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
909 | _("failed to set default file creation context to %s"), never executed: error (0, (*__errno_location ()) , dcgettext (((void *)0), "failed to set default file creation context to %s" , 5) , quote (con)); | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
910 | quote (con)); never executed: error (0, (*__errno_location ()) , dcgettext (((void *)0), "failed to set default file creation context to %s" , 5) , quote (con)); | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
911 | if (x->require_preserve_context)
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
912 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
913 | freecon (con); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
914 | return false; never executed: return 0 ; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
915 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
916 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
917 | freecon (con); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
918 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
919 | else | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
920 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
921 | if (all_errors || (some_errors && !errno_unsupported (errno)))
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
922 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
923 | error (0, errno, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
924 | _("failed to get security context of %s"), | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
925 | quoteaf (src_name)); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
926 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
927 | if (x->require_preserve_context)
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
928 | return false; never executed: return 0 ; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
929 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
930 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
931 | else if (x->set_security_context)
| 0-68505 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
932 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
933 | /* With -Z, adjust the default context for the process | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
934 | to have the type component adjusted as per the destination path. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
935 | if (new_dst && defaultcon (dst_name, mode) < 0
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
936 | && ! ignorable_ctx_err (errno))
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
937 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
938 | error (0, errno, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
939 | _("failed to set default file creation context for %s"), | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
940 | quoteaf (dst_name)); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
941 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
942 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
943 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
944 | return true; executed 68505 times by 3 tests: return 1 ; Executed by:
| 68505 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
945 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
946 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
947 | /* Reset the security context of DST_NAME, to that already set | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
948 | as the process default if PROCESS_LOCAL is true. Otherwise | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
949 | adjust the type component of DST_NAME's security context as | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
950 | per the system default for that path. Issue warnings upon | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
951 | failure, when allowed by various settings in CP_OPTIONS. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
952 | Return FALSE on failure, TRUE on success. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
953 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
954 | bool | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
955 | set_file_security_ctx (char const *dst_name, bool process_local, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
956 | bool recurse, const struct cp_options *x) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
957 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
958 | bool all_errors = (!x->data_copy_required
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
959 | || x->require_preserve_context);
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
960 | bool some_errors = !all_errors && !x->reduce_diagnostics;
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
961 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
962 | if (! restorecon (dst_name, recurse, process_local))
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
963 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
964 | if (all_errors || (some_errors && !errno_unsupported (errno)))
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
965 | error (0, errno, _("failed to set the security context of %s"), never executed: error (0, (*__errno_location ()) , dcgettext (((void *)0), "failed to set the security context of %s" , 5) , quotearg_n_style (0, shell_escape_always_quoting_style, dst_name)); | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
966 | quoteaf_n (0, dst_name)); never executed: error (0, (*__errno_location ()) , dcgettext (((void *)0), "failed to set the security context of %s" , 5) , quotearg_n_style (0, shell_escape_always_quoting_style, dst_name)); | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
967 | return false; never executed: return 0 ; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
968 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
969 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
970 | return true; never executed: return 1 ; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
971 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
972 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
973 | /* Change the file mode bits of the file identified by DESC or NAME to MODE. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
974 | Use DESC if DESC is valid and fchmod is available, NAME otherwise. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
975 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
976 | static int | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
977 | fchmod_or_lchmod (int desc, char const *name, mode_t mode) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
978 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
979 | #if HAVE_FCHMOD | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
980 | if (0 <= desc)
| 0-1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
981 | return fchmod (desc, mode); executed 1 time by 1 test: return fchmod (desc, mode); Executed by:
| 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
982 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
983 | return lchmod (name, mode); never executed: return chmod (name, mode); | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
984 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
985 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
986 | #ifndef HAVE_STRUCT_STAT_ST_BLOCKS | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
987 | # define HAVE_STRUCT_STAT_ST_BLOCKS 0 | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
988 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
989 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
990 | /* Use a heuristic to determine whether stat buffer SB comes from a file | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
991 | with sparse blocks. If the file has fewer blocks than would normally | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
992 | be needed for a file of its size, then at least one of the blocks in | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
993 | the file is a hole. In that case, return true. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
994 | static bool | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
995 | is_probably_sparse (struct stat const *sb) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
996 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
997 | return (HAVE_STRUCT_STAT_ST_BLOCKS executed 4455 times by 3 tests: return (1 && (((( sb->st_mode )) & 0170000) == (0100000)) && ((*sb).st_blocks) < sb->st_size / 512 ); Executed by:
| 4455 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
998 | && S_ISREG (sb->st_mode) executed 4455 times by 3 tests: return (1 && (((( sb->st_mode )) & 0170000) == (0100000)) && ((*sb).st_blocks) < sb->st_size / 512 ); Executed by:
| 4455 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
999 | && ST_NBLOCKS (*sb) < sb->st_size / ST_NBLOCKSIZE); executed 4455 times by 3 tests: return (1 && (((( sb->st_mode )) & 0170000) == (0100000)) && ((*sb).st_blocks) < sb->st_size / 512 ); Executed by:
| 4455 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1000 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1001 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1002 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1003 | /* Copy a regular file from SRC_NAME to DST_NAME. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1004 | If the source file contains holes, copies holes and blocks of zeros | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1005 | in the source file as holes in the destination file. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1006 | (Holes are read as zeroes by the 'read' system call.) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1007 | When creating the destination, use DST_MODE & ~OMITTED_PERMISSIONS | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1008 | as the third argument in the call to open, adding | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1009 | OMITTED_PERMISSIONS after copying as needed. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1010 | X provides many option settings. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1011 | Return true if successful. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1012 | *NEW_DST is as in copy_internal. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1013 | SRC_SB is the result of calling XSTAT (aka stat) on SRC_NAME. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1014 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1015 | static bool | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1016 | copy_reg (char const *src_name, char const *dst_name, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1017 | const struct cp_options *x, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1018 | mode_t dst_mode, mode_t omitted_permissions, bool *new_dst, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1019 | struct stat const *src_sb) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1020 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1021 | char *buf; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1022 | char *buf_alloc = NULL; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1023 | char *name_alloc = NULL; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1024 | int dest_desc; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1025 | int dest_errno; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1026 | int source_desc; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1027 | mode_t src_mode = src_sb->st_mode; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1028 | struct stat sb; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1029 | struct stat src_open_sb; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1030 | bool return_val = true; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1031 | bool data_copy_required = x->data_copy_required; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1032 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1033 | source_desc = open (src_name, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1034 | (O_RDONLY | O_BINARY | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1035 | | (x->dereference == DEREF_NEVER ? O_NOFOLLOW : 0))); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1036 | if (source_desc < 0)
| 1-4461 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1037 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1038 | error (0, errno, _("cannot open %s for reading"), quoteaf (src_name)); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1039 | return false; executed 1 time by 1 test: return 0 ; Executed by:
| 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1040 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1041 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1042 | if (fstat (source_desc, &src_open_sb) != 0)
| 0-4461 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1043 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1044 | error (0, errno, _("cannot fstat %s"), quoteaf (src_name)); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1045 | return_val = false; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1046 | goto close_src_desc; never executed: goto close_src_desc; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1047 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1048 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1049 | /* Compare the source dev/ino from the open file to the incoming, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1050 | saved ones obtained via a previous call to stat. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1051 | if (! SAME_INODE (*src_sb, src_open_sb))
| 0-4461 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1052 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1053 | error (0, 0, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1054 | _("skipping file %s, as it was replaced while being copied"), | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1055 | quoteaf (src_name)); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1056 | return_val = false; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1057 | goto close_src_desc; never executed: goto close_src_desc; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1058 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1059 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1060 | /* The semantics of the following open calls are mandated | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1061 | by the specs for both cp and mv. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1062 | if (! *new_dst)
| 98-4363 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1063 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1064 | int open_flags = | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1065 | O_WRONLY | O_BINARY | (x->data_copy_required ? O_TRUNC : 0); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1066 | dest_desc = open (dst_name, open_flags); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1067 | dest_errno = errno; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1068 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1069 | /* When using cp --preserve=context to copy to an existing destination, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1070 | reset the context as per the default context, which has already been | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1071 | set according to the src. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1072 | When using the mutually exclusive -Z option, then adjust the type of | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1073 | the existing context according to the system default for the dest. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1074 | Note we set the context here, _after_ the file is opened, lest the | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1075 | new context disallow that. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1076 | if ((x->set_security_context || x->preserve_security_context)
| 0-98 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1077 | && 0 <= dest_desc)
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1078 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1079 | if (! set_file_security_ctx (dst_name, x->preserve_security_context,
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1080 | false, x))
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1081 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1082 | if (x->require_preserve_context)
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1083 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1084 | return_val = false; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1085 | goto close_src_and_dst_desc; never executed: goto close_src_and_dst_desc; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1086 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1087 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1088 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1089 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1090 | if (dest_desc < 0 && x->unlink_dest_after_failed_open)
| 0-91 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1091 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1092 | if (unlink (dst_name) != 0)
| 0-7 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1093 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1094 | error (0, errno, _("cannot remove %s"), quoteaf (dst_name)); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1095 | return_val = false; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1096 | goto close_src_desc; never executed: goto close_src_desc; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1097 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1098 | if (x->verbose)
| 0-7 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1099 | printf (_("removed %s\n"), quoteaf (dst_name)); never executed: printf ( dcgettext (((void *)0), "removed %s\n" , 5) , quotearg_style (shell_escape_always_quoting_style, dst_name)); | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1100 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1101 | /* Tell caller that the destination file was unlinked. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1102 | *new_dst = true; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1103 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1104 | /* Ensure there is no race where a file may be left without | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1105 | an appropriate security context. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1106 | if (x->set_security_context)
| 0-7 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1107 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1108 | if (! set_process_security_ctx (src_name, dst_name, dst_mode,
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1109 | *new_dst, x))
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1110 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1111 | return_val = false; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1112 | goto close_src_desc; never executed: goto close_src_desc; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1113 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1114 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1115 | } executed 7 times by 1 test: end of block Executed by:
| 7 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1116 | } executed 98 times by 1 test: end of block Executed by:
| 98 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1117 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1118 | if (*new_dst)
| 91-4370 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1119 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1120 | open_with_O_CREAT:; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1121 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1122 | int open_flags = O_WRONLY | O_CREAT | O_BINARY; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1123 | dest_desc = open (dst_name, open_flags | O_EXCL, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1124 | dst_mode & ~omitted_permissions); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1125 | dest_errno = errno; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1126 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1127 | /* When trying to copy through a dangling destination symlink, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1128 | the above open fails with EEXIST. If that happens, and | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1129 | lstat'ing the DST_NAME shows that it is a symlink, then we | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1130 | have a problem: trying to resolve this dangling symlink to | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1131 | a directory/destination-entry pair is fundamentally racy, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1132 | so punt. If x->open_dangling_dest_symlink is set (cp sets | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1133 | that when POSIXLY_CORRECT is set in the environment), simply | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1134 | call open again, but without O_EXCL (potentially dangerous). | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1135 | If not, fail with a diagnostic. These shenanigans are necessary | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1136 | only when copying, i.e., not in move_mode. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1137 | if (dest_desc < 0 && dest_errno == EEXIST && ! x->move_mode)
| 0-4367 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1138 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1139 | struct stat dangling_link_sb; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1140 | if (lstat (dst_name, &dangling_link_sb) == 0
| 0-2 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1141 | && S_ISLNK (dangling_link_sb.st_mode))
| 0-2 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1142 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1143 | if (x->open_dangling_dest_symlink)
| 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1144 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1145 | dest_desc = open (dst_name, open_flags, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1146 | dst_mode & ~omitted_permissions); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1147 | dest_errno = errno; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1148 | } executed 1 time by 1 test: end of block Executed by:
| 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1149 | else | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1150 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1151 | error (0, 0, _("not writing through dangling symlink %s"), | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1152 | quoteaf (dst_name)); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1153 | return_val = false; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1154 | goto close_src_desc; executed 1 time by 1 test: goto close_src_desc; Executed by:
| 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1155 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1156 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1157 | } executed 1 time by 1 test: end of block Executed by:
| 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1158 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1159 | /* Improve quality of diagnostic when a nonexistent dst_name | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1160 | ends in a slash and open fails with errno == EISDIR. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1161 | if (dest_desc < 0 && dest_errno == EISDIR
| 0-4368 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1162 | && *dst_name && dst_name[strlen (dst_name) - 1] == '/')
| 0-1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1163 | dest_errno = ENOTDIR; executed 1 time by 1 test: dest_errno = 20 ; Executed by:
| 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1164 | } executed 4369 times by 3 tests: end of block Executed by:
| 4369 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1165 | else | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1166 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1167 | omitted_permissions = 0; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1168 | } executed 91 times by 1 test: end of block Executed by:
| 91 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1169 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1170 | if (dest_desc < 0)
| 1-4459 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1171 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1172 | /* If we've just failed due to ENOENT for an ostensibly preexisting | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1173 | destination (*new_dst was 0), that's a bit of a contradiction/race: | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1174 | the prior stat/lstat said the file existed (*new_dst was 0), yet | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1175 | the subsequent open-existing-file failed with ENOENT. With NFS, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1176 | the race window is wider still, since its meta-data caching tends | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1177 | to make the stat succeed for a just-removed remote file, while the | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1178 | more-definitive initial open call will fail with ENOENT. When this | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1179 | situation arises, we attempt to open again, but this time with | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1180 | O_CREAT. Do this only when not in move-mode, since when handling | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1181 | a cross-device move, we must never open an existing destination. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1182 | if (dest_errno == ENOENT && ! *new_dst && ! x->move_mode)
| 0-1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1183 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1184 | *new_dst = 1; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1185 | goto open_with_O_CREAT; never executed: goto open_with_O_CREAT; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1186 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1187 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1188 | /* Otherwise, it's an error. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1189 | error (0, dest_errno, _("cannot create regular file %s"), | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1190 | quoteaf (dst_name)); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1191 | return_val = false; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1192 | goto close_src_desc; executed 1 time by 1 test: goto close_src_desc; Executed by:
| 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1193 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1194 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1195 | if (fstat (dest_desc, &sb) != 0)
| 0-4459 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1196 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1197 | error (0, errno, _("cannot fstat %s"), quoteaf (dst_name)); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1198 | return_val = false; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1199 | goto close_src_and_dst_desc; never executed: goto close_src_and_dst_desc; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1200 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1201 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1202 | /* --attributes-only overrides --reflink. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1203 | if (data_copy_required && x->reflink_mode)
| 3-4456 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1204 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1205 | bool clone_ok = clone_file (dest_desc, source_desc) == 0; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1206 | if (clone_ok || x->reflink_mode == REFLINK_ALWAYS)
| 0-3923 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1207 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1208 | if (!clone_ok)
| 0-1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1209 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1210 | error (0, errno, _("failed to clone %s from %s"), | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1211 | quoteaf_n (0, dst_name), quoteaf_n (1, src_name)); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1212 | return_val = false; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1213 | goto close_src_and_dst_desc; executed 1 time by 1 test: goto close_src_and_dst_desc; Executed by:
| 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1214 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1215 | data_copy_required = false; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1216 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1217 | } executed 3922 times by 2 tests: end of block Executed by:
| 3922 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1218 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1219 | if (data_copy_required)
| 3-4455 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1220 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1221 | /* Choose a suitable buffer size; it may be adjusted later. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1222 | size_t buf_alignment = getpagesize (); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1223 | size_t buf_size = io_blksize (sb); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1224 | size_t hole_size = ST_BLKSIZE (sb);
| 0-4455 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1225 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1226 | fdadvise (source_desc, 0, 0, FADVISE_SEQUENTIAL); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1227 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1228 | /* Deal with sparse files. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1229 | bool make_holes = false; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1230 | bool sparse_src = is_probably_sparse (&src_open_sb); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1231 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1232 | if (S_ISREG (sb.st_mode))
| 1-4454 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1233 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1234 | /* Even with --sparse=always, try to create holes only | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1235 | if the destination is a regular file. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1236 | if (x->sparse_mode == SPARSE_ALWAYS)
| 76-4378 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1237 | make_holes = true; executed 76 times by 1 test: make_holes = 1 ; Executed by:
| 76 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1238 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1239 | /* Use a heuristic to determine whether SRC_NAME contains any sparse | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1240 | blocks. If the file has fewer blocks than would normally be | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1241 | needed for a file of its size, then at least one of the blocks in | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1242 | the file is a hole. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1243 | if (x->sparse_mode == SPARSE_AUTO && sparse_src)
| 8-4373 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1244 | make_holes = true; executed 8 times by 1 test: make_holes = 1 ; Executed by:
| 8 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1245 | } executed 4454 times by 3 tests: end of block Executed by:
| 4454 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1246 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1247 | /* If not making a sparse file, try to use a more-efficient | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1248 | buffer size. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1249 | if (! make_holes)
| 84-4371 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1250 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1251 | /* Compute the least common multiple of the input and output | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1252 | buffer sizes, adjusting for outlandish values. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1253 | size_t blcm_max = MIN (SIZE_MAX, SSIZE_MAX) - buf_alignment;
| 0-4371 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1254 | size_t blcm = buffer_lcm (io_blksize (src_open_sb), buf_size, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1255 | blcm_max); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1256 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1257 | /* Do not bother with a buffer larger than the input file, plus one | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1258 | byte to make sure the file has not grown while reading it. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1259 | if (S_ISREG (src_open_sb.st_mode) && src_open_sb.st_size < buf_size)
| 4-4367 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1260 | buf_size = src_open_sb.st_size + 1; executed 4356 times by 3 tests: buf_size = src_open_sb.st_size + 1; Executed by:
| 4356 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1261 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1262 | /* However, stick with a block size that is a positive multiple of | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1263 | blcm, overriding the above adjustments. Watch out for | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1264 | overflow. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1265 | buf_size += blcm - 1; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1266 | buf_size -= buf_size % blcm; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1267 | if (buf_size == 0 || blcm_max < buf_size)
| 0-4371 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1268 | buf_size = blcm; never executed: buf_size = blcm; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1269 | } executed 4371 times by 3 tests: end of block Executed by:
| 4371 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1270 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1271 | buf_alloc = xmalloc (buf_size + buf_alignment); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1272 | buf = ptr_align (buf_alloc, buf_alignment); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1273 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1274 | if (sparse_src)
| 65-4390 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1275 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1276 | bool normal_copy_required; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1277 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1278 | /* Perform an efficient extent-based copy, falling back to the | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1279 | standard copy only if the initial extent scan fails. If the | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1280 | '--sparse=never' option is specified, write all data but use | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1281 | any extents to read more efficiently. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1282 | if (extent_copy (source_desc, dest_desc, buf, buf_size, hole_size,
| 5-60 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1283 | src_open_sb.st_size,
| 5-60 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1284 | make_holes ? x->sparse_mode : SPARSE_NEVER,
| 5-60 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1285 | src_name, dst_name, &normal_copy_required))
| 5-60 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1286 | goto preserve_metadata; executed 60 times by 1 test: goto preserve_metadata; Executed by:
| 60 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1287 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1288 | if (! normal_copy_required)
| 0-5 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1289 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1290 | return_val = false; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1291 | goto close_src_and_dst_desc; never executed: goto close_src_and_dst_desc; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1292 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1293 | } executed 5 times by 1 test: end of block Executed by:
| 5 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1294 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1295 | off_t n_read; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1296 | bool wrote_hole_at_eof; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1297 | if (! sparse_copy (source_desc, dest_desc, buf, buf_size,
| 0-4395 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1298 | make_holes ? hole_size : 0,
| 0-4395 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1299 | x->sparse_mode == SPARSE_ALWAYS, src_name, dst_name,
| 0-4395 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1300 | UINTMAX_MAX, &n_read,
| 0-4395 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1301 | &wrote_hole_at_eof))
| 0-4395 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1302 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1303 | return_val = false; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1304 | goto close_src_and_dst_desc; never executed: goto close_src_and_dst_desc; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1305 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1306 | else if (wrote_hole_at_eof && ftruncate (dest_desc, n_read) < 0)
| 0-4387 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1307 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1308 | error (0, errno, _("failed to extend %s"), quoteaf (dst_name)); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1309 | return_val = false; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1310 | goto close_src_and_dst_desc; never executed: goto close_src_and_dst_desc; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1311 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1312 | } executed 4395 times by 3 tests: end of block Executed by:
| 4395 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1313 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1314 | preserve_metadata: code before this statement executed 4398 times by 3 tests: preserve_metadata: Executed by:
| 4398 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1315 | if (x->preserve_timestamps)
| 529-3929 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1316 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1317 | struct timespec timespec[2]; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1318 | timespec[0] = get_stat_atime (src_sb); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1319 | timespec[1] = get_stat_mtime (src_sb); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1320 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1321 | if (fdutimens (dest_desc, dst_name, timespec) != 0)
| 0-3929 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1322 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1323 | error (0, errno, _("preserving times for %s"), quoteaf (dst_name)); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1324 | if (x->require_preserve)
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1325 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1326 | return_val = false; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1327 | goto close_src_and_dst_desc; never executed: goto close_src_and_dst_desc; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1328 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1329 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1330 | } executed 3929 times by 2 tests: end of block Executed by:
| 3929 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1331 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1332 | /* Set ownership before xattrs as changing owners will | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1333 | clear capabilities. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1334 | if (x->preserve_ownership && ! SAME_OWNER_AND_GROUP (*src_sb, sb))
| 0-3930 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1335 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1336 | switch (set_owner (x, dst_name, dest_desc, src_sb, *new_dst, &sb)) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1337 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1338 | case -1: never executed: case -1: | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1339 | return_val = false; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1340 | goto close_src_and_dst_desc; never executed: goto close_src_and_dst_desc; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1341 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1342 | case 0: never executed: case 0: | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1343 | src_mode &= ~ (S_ISUID | S_ISGID | S_ISVTX); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1344 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1345 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1346 | } executed 1 time by 1 test: end of block Executed by:
| 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1347 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1348 | /* To allow copying xattrs on read-only files, temporarily chmod u+rw. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1349 | This workaround is required as an inode permission check is done | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1350 | by xattr_permission() in fs/xattr.c of the GNU/Linux kernel tree. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1351 | if (x->preserve_xattr)
| 536-3922 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1352 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1353 | bool access_changed = false; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1354 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1355 | if (!(sb.st_mode & S_IWUSR) && geteuid () != ROOT_UID)
| 0-3922 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1356 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1357 | access_changed = fchmod_or_lchmod (dest_desc, dst_name, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1358 | S_IRUSR | S_IWUSR) == 0; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1359 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1360 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1361 | if (!copy_attr (src_name, source_desc, dst_name, dest_desc, x)
| 0-3922 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1362 | && x->require_preserve_xattr)
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1363 | return_val = false; never executed: return_val = 0 ; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1364 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1365 | if (access_changed)
| 0-3922 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1366 | fchmod_or_lchmod (dest_desc, dst_name, dst_mode & ~omitted_permissions); never executed: fchmod_or_lchmod (dest_desc, dst_name, dst_mode & ~omitted_permissions); | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1367 | } executed 3922 times by 2 tests: end of block Executed by:
| 3922 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1368 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1369 | set_author (dst_name, dest_desc, src_sb); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1370 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1371 | if (x->preserve_mode || x->move_mode)
| 0-3930 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1372 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1373 | if (copy_acl (src_name, source_desc, dst_name, dest_desc, src_mode) != 0
| 0-3930 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1374 | && x->require_preserve)
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1375 | return_val = false; never executed: return_val = 0 ; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1376 | } executed 3930 times by 2 tests: end of block Executed by:
| 3930 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1377 | else if (x->set_mode)
| 22-506 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1378 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1379 | if (set_acl (dst_name, dest_desc, x->mode) != 0)
| 0-22 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1380 | return_val = false; never executed: return_val = 0 ; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1381 | } executed 22 times by 1 test: end of block Executed by:
| 22 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1382 | else if (x->explicit_no_preserve_mode)
| 3-503 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1383 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1384 | if (set_acl (dst_name, dest_desc, MODE_RW_UGO & ~cached_umask ()) != 0)
| 0-3 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1385 | return_val = false; never executed: return_val = 0 ; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1386 | } executed 3 times by 1 test: end of block Executed by:
| 3 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1387 | else if (omitted_permissions)
| 1-502 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1388 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1389 | omitted_permissions &= ~ cached_umask (); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1390 | if (omitted_permissions
| 0-1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1391 | && fchmod_or_lchmod (dest_desc, dst_name, dst_mode) != 0)
| 0-1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1392 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1393 | error (0, errno, _("preserving permissions for %s"), | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1394 | quoteaf (dst_name)); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1395 | if (x->require_preserve)
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1396 | return_val = false; never executed: return_val = 0 ; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1397 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1398 | } executed 1 time by 1 test: end of block Executed by:
| 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1399 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1400 | close_src_and_dst_desc: code before this statement executed 4458 times by 3 tests: close_src_and_dst_desc: Executed by:
| 4458 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1401 | if (close (dest_desc) < 0)
| 0-4459 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1402 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1403 | error (0, errno, _("failed to close %s"), quoteaf (dst_name)); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1404 | return_val = false; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1405 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1406 | close_src_desc: code before this statement executed 4459 times by 3 tests: close_src_desc: Executed by:
| 4459 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1407 | if (close (source_desc) < 0)
| 0-4461 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1408 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1409 | error (0, errno, _("failed to close %s"), quoteaf (src_name)); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1410 | return_val = false; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1411 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1412 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1413 | free (buf_alloc); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1414 | free (name_alloc); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1415 | return return_val; executed 4461 times by 3 tests: return return_val; Executed by:
| 4461 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1416 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1417 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1418 | /* Return true if it's ok that the source and destination | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1419 | files are the 'same' by some measure. The goal is to avoid | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1420 | making the 'copy' operation remove both copies of the file | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1421 | in that case, while still allowing the user to e.g., move or | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1422 | copy a regular file onto a symlink that points to it. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1423 | Try to minimize the cost of this function in the common case. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1424 | Set *RETURN_NOW if we've determined that the caller has no more | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1425 | work to do and should return successfully, right away. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1426 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1427 | static bool | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1428 | same_file_ok (char const *src_name, struct stat const *src_sb, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1429 | char const *dst_name, struct stat const *dst_sb, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1430 | const struct cp_options *x, bool *return_now) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1431 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1432 | const struct stat *src_sb_link; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1433 | const struct stat *dst_sb_link; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1434 | struct stat tmp_dst_sb; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1435 | struct stat tmp_src_sb; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1436 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1437 | bool same_link; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1438 | bool same = SAME_INODE (*src_sb, *dst_sb);
| 0-803 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1439 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1440 | *return_now = false; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1441 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1442 | /* FIXME: this should (at the very least) be moved into the following | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1443 | if-block. More likely, it should be removed, because it inhibits | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1444 | making backups. But removing it will result in a change in behavior | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1445 | that will probably have to be documented -- and tests will have to | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1446 | be updated. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1447 | if (same && x->hard_link)
| 23-803 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1448 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1449 | *return_now = true; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1450 | return true; executed 23 times by 1 test: return 1 ; Executed by:
| 23 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1451 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1452 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1453 | if (x->dereference == DEREF_NEVER)
| 208-651 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1454 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1455 | same_link = same; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1456 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1457 | /* If both the source and destination files are symlinks (and we'll | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1458 | know this here IFF preserving symlinks), then it's usually ok | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1459 | when they are distinct. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1460 | if (S_ISLNK (src_sb->st_mode) && S_ISLNK (dst_sb->st_mode))
| 15-619 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1461 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1462 | bool sn = same_name (src_name, dst_name); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1463 | if ( ! sn)
| 1-14 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1464 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1465 | /* It's fine when we're making any type of backup. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1466 | if (x->backup_type != no_backups)
| 5-9 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1467 | return true; executed 5 times by 2 tests: return 1 ; Executed by:
| 5 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1468 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1469 | /* Here we have two symlinks that are hard-linked together, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1470 | and we're not making backups. In this unusual case, simply | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1471 | returning true would lead to mv calling "rename(A,B)", | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1472 | which would do nothing and return 0. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1473 | if (same_link)
| 3-6 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1474 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1475 | *return_now = true; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1476 | return ! x->move_mode; executed 3 times by 2 tests: return ! x->move_mode; Executed by:
| 3 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1477 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1478 | } executed 6 times by 2 tests: end of block Executed by:
| 6 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1479 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1480 | return ! sn; executed 7 times by 2 tests: return ! sn; Executed by:
| 7 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1481 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1482 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1483 | src_sb_link = src_sb; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1484 | dst_sb_link = dst_sb; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1485 | } executed 636 times by 2 tests: end of block Executed by:
| 636 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1486 | else | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1487 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1488 | if (!same)
| 30-178 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1489 | return true; executed 178 times by 2 tests: return 1 ; Executed by:
| 178 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1490 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1491 | if (lstat (dst_name, &tmp_dst_sb) != 0
| 0-30 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1492 | || lstat (src_name, &tmp_src_sb) != 0)
| 0-30 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1493 | return true; never executed: return 1 ; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1494 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1495 | src_sb_link = &tmp_src_sb; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1496 | dst_sb_link = &tmp_dst_sb; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1497 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1498 | same_link = SAME_INODE (*src_sb_link, *dst_sb_link);
| 0-19 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1499 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1500 | /* If both are symlinks, then it's ok, but only if the destination | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1501 | will be unlinked before being opened. This is like the test | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1502 | above, but with the addition of the unlink_dest_before_opening | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1503 | conjunct because otherwise, with two symlinks to the same target, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1504 | we'd end up truncating the source file. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1505 | if (S_ISLNK (src_sb_link->st_mode) && S_ISLNK (dst_sb_link->st_mode)
| 4-17 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1506 | && x->unlink_dest_before_opening)
| 0-4 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1507 | return true; never executed: return 1 ; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1508 | } executed 30 times by 1 test: end of block Executed by:
| 30 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1509 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1510 | /* The backup code ensures there's a copy, so it's usually ok to | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1511 | remove any destination file. One exception is when both | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1512 | source and destination are the same directory entry. In that | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1513 | case, moving the destination file aside (in making the backup) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1514 | would also rename the source file and result in an error. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1515 | if (x->backup_type != no_backups)
| 56-610 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1516 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1517 | if (!same_link)
| 7-49 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1518 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1519 | /* In copy mode when dereferencing symlinks, if the source is a | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1520 | symlink and the dest is not, then backing up the destination | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1521 | (moving it aside) would make it a dangling symlink, and the | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1522 | subsequent attempt to open it in copy_reg would fail with | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1523 | a misleading diagnostic. Avoid that by returning zero in | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1524 | that case so the caller can make cp (or mv when it has to | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1525 | resort to reading the source file) fail now. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1526 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1527 | /* FIXME-note: even with the following kludge, we can still provoke | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1528 | the offending diagnostic. It's just a little harder to do :-) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1529 | $ rm -f a b c; touch c; ln -s c b; ln -s b a; cp -b a b | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1530 | cp: cannot open 'a' for reading: No such file or directory | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1531 | That's misleading, since a subsequent 'ls' shows that 'a' | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1532 | is still there. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1533 | One solution would be to open the source file *before* moving | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1534 | aside the destination, but that'd involve a big rewrite. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1535 | if ( ! x->move_mode
| 18-31 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1536 | && x->dereference != DEREF_NEVER
| 6-12 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1537 | && S_ISLNK (src_sb_link->st_mode)
| 0-6 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1538 | && ! S_ISLNK (dst_sb_link->st_mode))
| 0-6 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1539 | return false; executed 6 times by 1 test: return 0 ; Executed by:
| 6 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1540 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1541 | return true; executed 43 times by 2 tests: return 1 ; Executed by:
| 43 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1542 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1543 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1544 | /* FIXME: What about case insensitive file systems ? */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1545 | return ! same_name (src_name, dst_name); executed 7 times by 2 tests: return ! same_name (src_name, dst_name); Executed by:
| 7 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1546 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1547 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1548 | #if 0 | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1549 | /* FIXME: use or remove */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1550 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1551 | /* If we're making a backup, we'll detect the problem case in | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1552 | copy_reg because SRC_NAME will no longer exist. Allowing | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1553 | the test to be deferred lets cp do some useful things. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1554 | But when creating hardlinks and SRC_NAME is a symlink | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1555 | but DST_NAME is not we must test anyway. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1556 | if (x->hard_link | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1557 | || !S_ISLNK (src_sb_link->st_mode) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1558 | || S_ISLNK (dst_sb_link->st_mode)) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1559 | return true; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1560 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1561 | if (x->dereference != DEREF_NEVER) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1562 | return true; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1563 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1564 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1565 | if (x->move_mode || x->unlink_dest_before_opening)
| 10-545 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1566 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1567 | /* They may refer to the same file if we're in move mode and the | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1568 | target is a symlink. That is ok, since we remove any existing | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1569 | destination file before opening it -- via 'rename' if they're on | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1570 | the same file system, via 'unlink (DST_NAME)' otherwise. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1571 | if (S_ISLNK (dst_sb_link->st_mode))
| 6-549 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1572 | return true; executed 6 times by 2 tests: return 1 ; Executed by:
| 6 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1573 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1574 | /* It's not ok if they're distinct hard links to the same file as | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1575 | this causes a race condition and we may lose data in this case. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1576 | if (same_link
| 6-543 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1577 | && 1 < dst_sb_link->st_nlink
| 1-5 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1578 | && ! same_name (src_name, dst_name))
| 1-4 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1579 | return ! x->move_mode; executed 4 times by 2 tests: return ! x->move_mode; Executed by:
| 4 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1580 | } executed 545 times by 2 tests: end of block Executed by:
| 545 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1581 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1582 | /* If neither is a symlink, then it's ok as long as they aren't | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1583 | hard links to the same file. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1584 | if (!S_ISLNK (src_sb_link->st_mode) && !S_ISLNK (dst_sb_link->st_mode))
| 6-578 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1585 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1586 | if (!SAME_INODE (*src_sb_link, *dst_sb_link))
| 0-555 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1587 | return true; executed 555 times by 2 tests: return 1 ; Executed by:
| 555 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1588 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1589 | /* If they are the same file, it's ok if we're making hard links. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1590 | if (x->hard_link)
| 0-17 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1591 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1592 | *return_now = true; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1593 | return true; never executed: return 1 ; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1594 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1595 | } executed 17 times by 2 tests: end of block Executed by:
| 17 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1596 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1597 | /* At this point, it is normally an error (data loss) to move a symlink | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1598 | onto its referent, but in at least one narrow case, it is not: | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1599 | In move mode, when | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1600 | 1) src is a symlink, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1601 | 2) dest has a link count of 2 or more and | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1602 | 3) dest and the referent of src are not the same directory entry, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1603 | then it's ok, since while we'll lose one of those hard links, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1604 | src will still point to a remaining link. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1605 | Note that technically, condition #3 obviates condition #2, but we | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1606 | retain the 1 < st_nlink condition because that means fewer invocations | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1607 | of the more expensive #3. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1608 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1609 | Given this, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1610 | $ touch f && ln f l && ln -s f s | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1611 | $ ls -og f l s | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1612 | -rw-------. 2 0 Jan 4 22:46 f | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1613 | -rw-------. 2 0 Jan 4 22:46 l | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1614 | lrwxrwxrwx. 1 1 Jan 4 22:46 s -> f | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1615 | this must fail: mv s f | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1616 | this must succeed: mv s l */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1617 | if (x->move_mode
| 5-40 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1618 | && S_ISLNK (src_sb->st_mode)
| 1-4 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1619 | && 1 < dst_sb_link->st_nlink)
| 1-3 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1620 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1621 | char *abs_src = canonicalize_file_name (src_name); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1622 | if (abs_src)
| 0-1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1623 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1624 | bool result = ! same_name (abs_src, dst_name); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1625 | free (abs_src); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1626 | return result; executed 1 time by 1 test: return result; Executed by:
| 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1627 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1628 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1629 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1630 | /* It's ok to remove a destination symlink. But that works only | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1631 | when creating symbolic links, or when the source and destination | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1632 | are on the same file system and when creating hard links or when | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1633 | unlinking before opening the destination. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1634 | if (x->symbolic_link
| 0-44 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1635 | || ((x->hard_link || x->unlink_dest_before_opening)
| 3-41 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1636 | && S_ISLNK (dst_sb_link->st_mode)))
| 2-7 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1637 | return dst_sb_link->st_dev == src_sb_link->st_dev; executed 2 times by 1 test: return dst_sb_link->st_dev == src_sb_link->st_dev; Executed by:
| 2 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1638 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1639 | if (x->dereference == DEREF_NEVER)
| 20-22 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1640 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1641 | if ( ! S_ISLNK (src_sb_link->st_mode))
| 10-12 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1642 | tmp_src_sb = *src_sb_link; executed 12 times by 2 tests: tmp_src_sb = *src_sb_link; Executed by:
| 12 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1643 | else if (stat (src_name, &tmp_src_sb) != 0)
| 0-10 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1644 | return true; never executed: return 1 ; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1645 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1646 | if ( ! S_ISLNK (dst_sb_link->st_mode))
| 0-22 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1647 | tmp_dst_sb = *dst_sb_link; executed 22 times by 2 tests: tmp_dst_sb = *dst_sb_link; Executed by:
| 22 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1648 | else if (stat (dst_name, &tmp_dst_sb) != 0)
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1649 | return true; never executed: return 1 ; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1650 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1651 | if ( ! SAME_INODE (tmp_src_sb, tmp_dst_sb))
| 0-22 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1652 | return true; never executed: return 1 ; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1653 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1654 | /* FIXME: shouldn't this be testing whether we're making symlinks? */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1655 | if (x->hard_link)
| 1-21 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1656 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1657 | *return_now = true; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1658 | return true; executed 1 time by 1 test: return 1 ; Executed by:
| 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1659 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1660 | } executed 21 times by 2 tests: end of block Executed by:
| 21 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1661 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1662 | return false; executed 41 times by 2 tests: return 0 ; Executed by:
| 41 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1663 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1664 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1665 | /* Return true if FILE, with mode MODE, is writable in the sense of 'mv'. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1666 | Always consider a symbolic link to be writable. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1667 | static bool | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1668 | writable_destination (char const *file, mode_t mode) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1669 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1670 | return (S_ISLNK (mode) executed 13 times by 2 tests: return ( (((( mode )) & 0170000) == (0120000)) || can_write_any_file () || euidaccess (file, 2 ) == 0); Executed by:
| 13 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1671 | || can_write_any_file () executed 13 times by 2 tests: return ( (((( mode )) & 0170000) == (0120000)) || can_write_any_file () || euidaccess (file, 2 ) == 0); Executed by:
| 13 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1672 | || euidaccess (file, W_OK) == 0); executed 13 times by 2 tests: return ( (((( mode )) & 0170000) == (0120000)) || can_write_any_file () || euidaccess (file, 2 ) == 0); Executed by:
| 13 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1673 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1674 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1675 | static bool | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1676 | overwrite_ok (struct cp_options const *x, char const *dst_name, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1677 | struct stat const *dst_sb) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1678 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1679 | if (! writable_destination (dst_name, dst_sb->st_mode))
| 3-10 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1680 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1681 | char perms[12]; /* "-rwxrwxrwx " ls-style modes. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1682 | strmode (dst_sb->st_mode, perms); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1683 | perms[10] = '\0'; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1684 | fprintf (stderr, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1685 | (x->move_mode || x->unlink_dest_before_opening | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1686 | || x->unlink_dest_after_failed_open) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1687 | ? _("%s: replace %s, overriding mode %04lo (%s)? ") | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1688 | : _("%s: unwritable %s (mode %04lo, %s); try anyway? "), | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1689 | program_name, quoteaf (dst_name), | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1690 | (unsigned long int) (dst_sb->st_mode & CHMOD_MODE_BITS), | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1691 | &perms[1]); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1692 | } executed 3 times by 2 tests: end of block Executed by:
| 3 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1693 | else | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1694 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1695 | fprintf (stderr, _("%s: overwrite %s? "), | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1696 | program_name, quoteaf (dst_name)); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1697 | } executed 10 times by 2 tests: end of block Executed by:
| 10 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1698 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1699 | return yesno (); executed 13 times by 2 tests: return yesno (); Executed by:
| 13 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1700 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1701 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1702 | /* Initialize the hash table implementing a set of F_triple entries | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1703 | corresponding to destination files. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1704 | extern void | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1705 | dest_info_init (struct cp_options *x) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1706 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1707 | x->dest_info | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1708 | = hash_initialize (DEST_INFO_INITIAL_CAPACITY, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1709 | NULL, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1710 | triple_hash, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1711 | triple_compare, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1712 | triple_free); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1713 | } executed 42 times by 3 tests: end of block Executed by:
| 42 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1714 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1715 | /* Initialize the hash table implementing a set of F_triple entries | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1716 | corresponding to source files listed on the command line. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1717 | extern void | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1718 | src_info_init (struct cp_options *x) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1719 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1720 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1721 | /* Note that we use triple_hash_no_name here. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1722 | Contrast with the use of triple_hash above. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1723 | That is necessary because a source file may be specified | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1724 | in many different ways. We want to warn about this | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1725 | cp a a d/ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1726 | as well as this: | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1727 | cp a ./a d/ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1728 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1729 | x->src_info | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1730 | = hash_initialize (DEST_INFO_INITIAL_CAPACITY, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1731 | NULL, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1732 | triple_hash_no_name, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1733 | triple_compare, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1734 | triple_free); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1735 | } executed 19 times by 1 test: end of block Executed by:
| 19 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1736 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1737 | /* When effecting a move (e.g., for mv(1)), and given the name DST_NAME | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1738 | of the destination and a corresponding stat buffer, DST_SB, return | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1739 | true if the logical 'move' operation should _not_ proceed. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1740 | Otherwise, return false. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1741 | Depending on options specified in X, this code may issue an | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1742 | interactive prompt asking whether it's ok to overwrite DST_NAME. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1743 | static bool | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1744 | abandon_move (const struct cp_options *x, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1745 | char const *dst_name, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1746 | struct stat const *dst_sb) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1747 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1748 | assert (x->move_mode); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1749 | return (x->interactive == I_ALWAYS_NO executed 572 times by 1 test: return (x->interactive == I_ALWAYS_NO || ((x->interactive == I_ASK_USER || (x->interactive == I_UNSPECIFIED && x->stdin_tty && ! writable_destination (dst_name, dst_sb->st_mode))) && ! overwrite_ok (x, dst_name, dst_sb))); Executed by:
| 572 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1750 | || ((x->interactive == I_ASK_USER executed 572 times by 1 test: return (x->interactive == I_ALWAYS_NO || ((x->interactive == I_ASK_USER || (x->interactive == I_UNSPECIFIED && x->stdin_tty && ! writable_destination (dst_name, dst_sb->st_mode))) && ! overwrite_ok (x, dst_name, dst_sb))); Executed by:
| 572 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1751 | || (x->interactive == I_UNSPECIFIED executed 572 times by 1 test: return (x->interactive == I_ALWAYS_NO || ((x->interactive == I_ASK_USER || (x->interactive == I_UNSPECIFIED && x->stdin_tty && ! writable_destination (dst_name, dst_sb->st_mode))) && ! overwrite_ok (x, dst_name, dst_sb))); Executed by:
| 572 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1752 | && x->stdin_tty executed 572 times by 1 test: return (x->interactive == I_ALWAYS_NO || ((x->interactive == I_ASK_USER || (x->interactive == I_UNSPECIFIED && x->stdin_tty && ! writable_destination (dst_name, dst_sb->st_mode))) && ! overwrite_ok (x, dst_name, dst_sb))); Executed by:
| 572 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1753 | && ! writable_destination (dst_name, dst_sb->st_mode))) executed 572 times by 1 test: return (x->interactive == I_ALWAYS_NO || ((x->interactive == I_ASK_USER || (x->interactive == I_UNSPECIFIED && x->stdin_tty && ! writable_destination (dst_name, dst_sb->st_mode))) && ! overwrite_ok (x, dst_name, dst_sb))); Executed by:
| 572 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1754 | && ! overwrite_ok (x, dst_name, dst_sb))); executed 572 times by 1 test: return (x->interactive == I_ALWAYS_NO || ((x->interactive == I_ASK_USER || (x->interactive == I_UNSPECIFIED && x->stdin_tty && ! writable_destination (dst_name, dst_sb->st_mode))) && ! overwrite_ok (x, dst_name, dst_sb))); Executed by:
| 572 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1755 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1756 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1757 | /* Print --verbose output on standard output, e.g. 'new' -> 'old'. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1758 | If BACKUP_DST_NAME is non-NULL, then also indicate that it is | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1759 | the name of a backup file. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1760 | static void | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1761 | emit_verbose (char const *src, char const *dst, char const *backup_dst_name) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1762 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1763 | printf ("%s -> %s", quoteaf_n (0, src), quoteaf_n (1, dst)); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1764 | if (backup_dst_name)
| 1-19 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1765 | printf (_(" (backup: %s)"), quoteaf (backup_dst_name)); executed 1 time by 1 test: printf ( dcgettext (((void *)0), " (backup: %s)" , 5) , quotearg_style (shell_escape_always_quoting_style, backup_dst_name)); Executed by:
| 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1766 | putchar ('\n'); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1767 | } executed 20 times by 3 tests: end of block Executed by:
| 20 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1768 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1769 | /* A wrapper around "setfscreatecon (NULL)" that exits upon failure. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1770 | static void | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1771 | restore_default_fscreatecon_or_die (void) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1772 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1773 | if (setfscreatecon (NULL) != 0)
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1774 | die (EXIT_FAILURE, errno, never executed: ((!!sizeof (struct { _Static_assert ( 1 , "verify_expr (" "1" ", " "(error (1, (*__errno_location ()), dcgettext (((void *)0), \"failed to restore the default file creation context\", 5)), assume (false))" ")"); int _gl_dummy; })) ? ((error ( 1 , (*__errn...ile creation context" , 5) ), (( 0 ) ? (void) 0 : __builtin_unreachable ()))) : ((error ( 1 , (*__errno_location ()) , dcgettext (((void *)0), "failed to restore the default file creation context" , 5) ), (( 0 ) ? (void) 0 : __builtin_unreachable ())))) ; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1775 | _("failed to restore the default file creation context")); never executed: ((!!sizeof (struct { _Static_assert ( 1 , "verify_expr (" "1" ", " "(error (1, (*__errno_location ()), dcgettext (((void *)0), \"failed to restore the default file creation context\", 5)), assume (false))" ")"); int _gl_dummy; })) ? ((error ( 1 , (*__errn...ile creation context" , 5) ), (( 0 ) ? (void) 0 : __builtin_unreachable ()))) : ((error ( 1 , (*__errno_location ()) , dcgettext (((void *)0), "failed to restore the default file creation context" , 5) ), (( 0 ) ? (void) 0 : __builtin_unreachable ())))) ; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1776 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1777 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1778 | /* Create a hard link DST_NAME to SRC_NAME, honoring the REPLACE, VERBOSE and | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1779 | DEREFERENCE settings. Return true upon success. Otherwise, diagnose the | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1780 | failure and return false. If SRC_NAME is a symbolic link, then it will not | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1781 | be followed unless DEREFERENCE is true. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1782 | If the system doesn't support hard links to symbolic links, then DST_NAME | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1783 | will be created as a symbolic link to SRC_NAME. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1784 | static bool | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1785 | create_hard_link (char const *src_name, char const *dst_name, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1786 | bool replace, bool verbose, bool dereference) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1787 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1788 | int status = force_linkat (AT_FDCWD, src_name, AT_FDCWD, dst_name, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1789 | dereference ? AT_SYMLINK_FOLLOW : 0, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1790 | replace); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1791 | if (status < 0)
| 5-30051 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1792 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1793 | error (0, errno, _("cannot create hard link %s to %s"), | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1794 | quoteaf_n (0, dst_name), quoteaf_n (1, src_name)); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1795 | return false; executed 5 times by 1 test: return 0 ; Executed by:
| 5 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1796 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1797 | if (0 < status && verbose)
| 0-30035 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1798 | printf (_("removed %s\n"), quoteaf (dst_name)); never executed: printf ( dcgettext (((void *)0), "removed %s\n" , 5) , quotearg_style (shell_escape_always_quoting_style, dst_name)); | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1799 | return true; executed 30051 times by 2 tests: return 1 ; Executed by:
| 30051 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1800 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1801 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1802 | /* Return true if the current file should be (tried to be) dereferenced: | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1803 | either for DEREF_ALWAYS or for DEREF_COMMAND_LINE_ARGUMENTS in the case | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1804 | where the current file is a COMMAND_LINE_ARG; otherwise return false. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1805 | static inline bool _GL_ATTRIBUTE_PURE | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1806 | should_dereference (const struct cp_options *x, bool command_line_arg) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1807 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1808 | return x->dereference == DEREF_ALWAYS executed 69216 times by 3 tests: return x->dereference == DEREF_ALWAYS || (x->dereference == DEREF_COMMAND_LINE_ARGUMENTS && command_line_arg); Executed by:
| 69216 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1809 | || (x->dereference == DEREF_COMMAND_LINE_ARGUMENTS executed 69216 times by 3 tests: return x->dereference == DEREF_ALWAYS || (x->dereference == DEREF_COMMAND_LINE_ARGUMENTS && command_line_arg); Executed by:
| 69216 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1810 | && command_line_arg); executed 69216 times by 3 tests: return x->dereference == DEREF_ALWAYS || (x->dereference == DEREF_COMMAND_LINE_ARGUMENTS && command_line_arg); Executed by:
| 69216 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1811 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1812 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1813 | /* Return true if the source file with basename SRCBASE and status SRC_ST | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1814 | is likely to be the simple backup file for DST_NAME. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1815 | static bool | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1816 | source_is_dst_backup (char const *srcbase, struct stat const *src_st, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1817 | char const *dst_name) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1818 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1819 | size_t srcbaselen = strlen (srcbase); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1820 | char const *dstbase = last_component (dst_name); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1821 | size_t dstbaselen = strlen (dstbase); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1822 | size_t suffixlen = strlen (simple_backup_suffix); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1823 | if (! (srcbaselen == dstbaselen + suffixlen
| 10-41 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1824 | && memcmp (srcbase, dstbase, dstbaselen) == 0
| 2-8 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1825 | && STREQ (srcbase + dstbaselen, simple_backup_suffix))) never executed: __result = (((const unsigned char *) (const char *) ( srcbase + dstbaselen ))[3] - __s2[3]); never executed: end of block never executed: end of block never executed: __result = (((const unsigned char *) (const char *) ( simple_backup_suffix ))[3] - __s2[3]); never executed: end of block never executed: end of block
| 0-2 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1826 | return false; executed 49 times by 3 tests: return 0 ; Executed by:
| 49 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1827 | size_t dstlen = strlen (dst_name); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1828 | char *dst_back = xmalloc (dstlen + suffixlen + 1); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1829 | strcpy (mempcpy (dst_back, dst_name, dstlen), simple_backup_suffix); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1830 | struct stat dst_back_sb; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1831 | int dst_back_status = stat (dst_back, &dst_back_sb); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1832 | free (dst_back); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1833 | return dst_back_status == 0 && SAME_INODE (*src_st, dst_back_sb); executed 2 times by 2 tests: return dst_back_status == 0 && ((*src_st).st_ino == (dst_back_sb).st_ino && (*src_st).st_dev == (dst_back_sb).st_dev); Executed by:
| 2 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1834 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1835 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1836 | /* Copy the file SRC_NAME to the file DST_NAME. The files may be of | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1837 | any type. NEW_DST should be true if the file DST_NAME cannot | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1838 | exist because its parent directory was just created; NEW_DST should | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1839 | be false if DST_NAME might already exist. A non-null PARENT describes the | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1840 | parent directory. ANCESTORS points to a linked, null terminated list of | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1841 | devices and inodes of parent directories of SRC_NAME. COMMAND_LINE_ARG | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1842 | is true iff SRC_NAME was specified on the command line. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1843 | FIRST_DIR_CREATED_PER_COMMAND_LINE_ARG is both input and output. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1844 | Set *COPY_INTO_SELF if SRC_NAME is a parent of (or the | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1845 | same as) DST_NAME; otherwise, clear it. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1846 | Return true if successful. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1847 | static bool | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1848 | copy_internal (char const *src_name, char const *dst_name, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1849 | bool new_dst, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1850 | struct stat const *parent, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1851 | struct dir_list *ancestors, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1852 | const struct cp_options *x, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1853 | bool command_line_arg, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1854 | bool *first_dir_created_per_command_line_arg, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1855 | bool *copy_into_self, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1856 | bool *rename_succeeded) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1857 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1858 | struct stat src_sb; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1859 | struct stat dst_sb; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1860 | mode_t src_mode IF_LINT ( = 0); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1861 | mode_t dst_mode IF_LINT ( = 0); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1862 | mode_t dst_mode_bits; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1863 | mode_t omitted_permissions; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1864 | bool restore_dst_mode = false; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1865 | char *earlier_file = NULL; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1866 | char *dst_backup = NULL; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1867 | bool delayed_ok; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1868 | bool copied_as_regular = false; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1869 | bool dest_is_symlink = false; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1870 | bool have_dst_lstat = false; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1871 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1872 | *copy_into_self = false; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1873 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1874 | int rename_errno = x->rename_errno; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1875 | if (x->move_mode)
| 8458-60773 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1876 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1877 | if (rename_errno < 0)
| 584-7874 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1878 | rename_errno = (renameat2 (AT_FDCWD, src_name, AT_FDCWD, dst_name, executed 7874 times by 1 test: rename_errno = (renameat2 ( -100 , src_name, -100 , dst_name, (1 << 0) ) ? (*__errno_location ()) : 0); Executed by:
| 12-7874 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1879 | RENAME_NOREPLACE) executed 7874 times by 1 test: rename_errno = (renameat2 ( -100 , src_name, -100 , dst_name, (1 << 0) ) ? (*__errno_location ()) : 0); Executed by:
| 12-7874 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1880 | ? errno : 0); executed 7874 times by 1 test: rename_errno = (renameat2 ( -100 , src_name, -100 , dst_name, (1 << 0) ) ? (*__errno_location ()) : 0); Executed by:
| 7874 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1881 | new_dst = rename_errno == 0; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1882 | if (rename_succeeded)
| 3919-4539 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1883 | *rename_succeeded = new_dst; executed 4539 times by 1 test: *rename_succeeded = new_dst; Executed by:
| 4539 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1884 | } executed 8458 times by 1 test: end of block Executed by:
| 8458 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1885 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1886 | if (rename_errno == 0
| 28-69203 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1887 | ? !x->last_file
| 28-69203 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1888 | : rename_errno != EEXIST || x->interactive != I_ALWAYS_NO)
| 3-69203 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1889 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1890 | char const *name = rename_errno == 0 ? dst_name : src_name;
| 7-69196 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1891 | if (XSTAT (x, name, &src_sb) != 0)
| 9-69194 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1892 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1893 | error (0, errno, _("cannot stat %s"), quoteaf (name)); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1894 | return false; executed 9 times by 2 tests: return 0 ; Executed by:
| 9 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1895 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1896 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1897 | src_mode = src_sb.st_mode; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1898 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1899 | if (S_ISDIR (src_mode) && !x->recursive)
| 4-35194 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1900 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1901 | error (0, 0, ! x->install_mode /* cp */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1902 | ? _("-r not specified; omitting directory %s") | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1903 | : _("omitting directory %s"), | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1904 | quoteaf (src_name)); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1905 | return false; executed 4 times by 2 tests: return 0 ; Executed by:
| 4 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1906 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1907 | } executed 69190 times by 3 tests: end of block Executed by:
| 69190 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1908 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1909 | /* Detect the case in which the same source file appears more than | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1910 | once on the command line and no backup option has been selected. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1911 | If so, simply warn and don't copy it the second time. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1912 | This check is enabled only if x->src_info is non-NULL. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1913 | if (command_line_arg && x->src_info)
| 40-63958 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1914 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1915 | if ( ! S_ISDIR (src_sb.st_mode)
| 11-29 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1916 | && x->backup_type == no_backups
| 6-23 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1917 | && seen_file (x->src_info, src_name, &src_sb))
| 2-21 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1918 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1919 | error (0, 0, _("warning: source file %s specified more than once"), | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1920 | quoteaf (src_name)); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1921 | return true; executed 2 times by 1 test: return 1 ; Executed by:
| 2 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1922 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1923 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1924 | record_file (x->src_info, src_name, &src_sb); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1925 | } executed 38 times by 1 test: end of block Executed by:
| 38 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1926 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1927 | bool dereference = should_dereference (x, command_line_arg); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1928 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1929 | if (!new_dst)
| 9157-60059 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1930 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1931 | if (! (rename_errno == EEXIST && x->interactive == I_ALWAYS_NO))
| 3-8589 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1932 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1933 | /* Regular files can be created by writing through symbolic | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1934 | links, but other files cannot. So use stat on the | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1935 | destination when copying a regular file, and lstat otherwise. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1936 | However, if we intend to unlink or remove the destination | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1937 | first, use lstat, since a copy won't actually be made to the | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1938 | destination in that case. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1939 | bool use_lstat | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1940 | = ((! S_ISREG (src_mode)
| 4034-5120 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1941 | && (! x->copy_as_regular
| 34-4000 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1942 | || S_ISDIR (src_mode) || S_ISLNK (src_mode)))
|