OpenCoverage

mv.c

Absolute File Name:/home/opencoverage/opencoverage/guest-scripts/coreutils/src/src/mv.c
Source codeSwitch to Preprocessed file
LineSourceCount
1/* mv -- move or rename files-
2 Copyright (C) 1986-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/* Written by Mike Parker, David MacKenzie, and Jim Meyering */-
18-
19#include <config.h>-
20#include <stdio.h>-
21#include <getopt.h>-
22#include <sys/types.h>-
23#include <assert.h>-
24#include <selinux/selinux.h>-
25-
26#include "system.h"-
27#include "backupfile.h"-
28#include "copy.h"-
29#include "cp-hash.h"-
30#include "die.h"-
31#include "error.h"-
32#include "filenamecat.h"-
33#include "remove.h"-
34#include "renameat2.h"-
35#include "root-dev-ino.h"-
36#include "priv-set.h"-
37-
38/* The official name of this program (e.g., no 'g' prefix). */-
39#define PROGRAM_NAME "mv"-
40-
41#define AUTHORS \-
42 proper_name ("Mike Parker"), \-
43 proper_name ("David MacKenzie"), \-
44 proper_name ("Jim Meyering")-
45-
46/* For long options that have no equivalent short option, use a-
47 non-character as a pseudo short option, starting with CHAR_MAX + 1. */-
48enum-
49{-
50 STRIP_TRAILING_SLASHES_OPTION = CHAR_MAX + 1-
51};-
52-
53/* Remove any trailing slashes from each SOURCE argument. */-
54static bool remove_trailing_slashes;-
55-
56static struct option const long_options[] =-
57{-
58 {"backup", optional_argument, NULL, 'b'},-
59 {"context", no_argument, NULL, 'Z'},-
60 {"force", no_argument, NULL, 'f'},-
61 {"interactive", no_argument, NULL, 'i'},-
62 {"no-clobber", no_argument, NULL, 'n'},-
63 {"no-target-directory", no_argument, NULL, 'T'},-
64 {"strip-trailing-slashes", no_argument, NULL, STRIP_TRAILING_SLASHES_OPTION},-
65 {"suffix", required_argument, NULL, 'S'},-
66 {"target-directory", required_argument, NULL, 't'},-
67 {"update", no_argument, NULL, 'u'},-
68 {"verbose", no_argument, NULL, 'v'},-
69 {GETOPT_HELP_OPTION_DECL},-
70 {GETOPT_VERSION_OPTION_DECL},-
71 {NULL, 0, NULL, 0}-
72};-
73-
74static void-
75rm_option_init (struct rm_options *x)-
76{-
77 x->ignore_missing_files = false;-
78 x->remove_empty_directories = true;-
79 x->recursive = true;-
80 x->one_file_system = false;-
81-
82 /* Should we prompt for removal, too? No. Prompting for the 'move'-
83 part is enough. It implies removal. */-
84 x->interactive = RMI_NEVER;-
85 x->stdin_tty = false;-
86-
87 x->verbose = false;-
88-
89 /* Since this program may well have to process additional command-
90 line arguments after any call to 'rm', that function must preserve-
91 the initial working directory, in case one of those is a-
92 '.'-relative name. */-
93 x->require_restore_cwd = true;-
94-
95 {-
96 static struct dev_ino dev_ino_buf;-
97 x->root_dev_ino = get_root_dev_ino (&dev_ino_buf);-
98 if (x->root_dev_ino == NULL)
x->root_dev_ino == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 3926 times by 1 test
Evaluated by:
  • mv
0-3926
99 die (EXIT_FAILURE, errno, _("failed to get attributes of %s"),
never executed: ((!!sizeof (struct { _Static_assert ( 1 , "verify_expr (" "1" ", " "(error (1, (*__errno_location ()), dcgettext (((void *)0), \"failed to get attributes of %s\", 5), quotearg_style (shell_escape_always_quoting_style, \"/\")), assume (false))" ")"); int _... ? (void) 0 : __builtin_unreachable ()))) : ((error ( 1 , (*__errno_location ()) , dcgettext (((void *)0), "failed to get attributes of %s" , 5) , quotearg_style (shell_escape_always_quoting_style, "/")), (( 0 ) ? (void) 0 : __builtin_unreachable ())))) ;
0
100 quoteaf ("/"));
never executed: ((!!sizeof (struct { _Static_assert ( 1 , "verify_expr (" "1" ", " "(error (1, (*__errno_location ()), dcgettext (((void *)0), \"failed to get attributes of %s\", 5), quotearg_style (shell_escape_always_quoting_style, \"/\")), assume (false))" ")"); int _... ? (void) 0 : __builtin_unreachable ()))) : ((error ( 1 , (*__errno_location ()) , dcgettext (((void *)0), "failed to get attributes of %s" , 5) , quotearg_style (shell_escape_always_quoting_style, "/")), (( 0 ) ? (void) 0 : __builtin_unreachable ())))) ;
0
101 }-
102}
executed 3926 times by 1 test: end of block
Executed by:
  • mv
3926
103-
104static void-
105cp_option_init (struct cp_options *x)-
106{-
107 bool selinux_enabled = (0 < is_selinux_enabled ());-
108-
109 cp_options_default (x);-
110 x->copy_as_regular = false; /* FIXME: maybe make this an option */-
111 x->reflink_mode = REFLINK_AUTO;-
112 x->dereference = DEREF_NEVER;-
113 x->unlink_dest_before_opening = false;-
114 x->unlink_dest_after_failed_open = false;-
115 x->hard_link = false;-
116 x->interactive = I_UNSPECIFIED;-
117 x->move_mode = true;-
118 x->install_mode = false;-
119 x->one_file_system = false;-
120 x->preserve_ownership = true;-
121 x->preserve_links = true;-
122 x->preserve_mode = true;-
123 x->preserve_timestamps = true;-
124 x->explicit_no_preserve_mode= false;-
125 x->preserve_security_context = selinux_enabled;-
126 x->set_security_context = false;-
127 x->reduce_diagnostics = false;-
128 x->data_copy_required = true;-
129 x->require_preserve = false; /* FIXME: maybe make this an option */-
130 x->require_preserve_context = false;-
131 x->preserve_xattr = true;-
132 x->require_preserve_xattr = false;-
133 x->recursive = true;-
134 x->sparse_mode = SPARSE_AUTO; /* FIXME: maybe make this an option */-
135 x->symbolic_link = false;-
136 x->set_mode = false;-
137 x->mode = 0;-
138 x->stdin_tty = isatty (STDIN_FILENO);-
139-
140 x->open_dangling_dest_symlink = false;-
141 x->update = false;-
142 x->verbose = false;-
143 x->dest_info = NULL;-
144 x->src_info = NULL;-
145}
executed 697 times by 1 test: end of block
Executed by:
  • mv
697
146-
147/* FILE is the last operand of this command. Return true if FILE is a-
148 directory. But report an error if there is a problem accessing FILE, other-
149 than nonexistence (errno == ENOENT). */-
150-
151static bool-
152target_directory_operand (char const *file)-
153{-
154 struct stat st;-
155 int err = (stat (file, &st) == 0 ? 0 : errno);
stat (file, &st) == 0Description
TRUEevaluated 592 times by 1 test
Evaluated by:
  • mv
FALSEevaluated 1 time by 1 test
Evaluated by:
  • mv
1-592
156 bool is_a_dir = !err && S_ISDIR (st.st_mode);
!errDescription
TRUEevaluated 592 times by 1 test
Evaluated by:
  • mv
FALSEevaluated 1 time by 1 test
Evaluated by:
  • mv
(((( st.st_mod... == (0040000))Description
TRUEevaluated 27 times by 1 test
Evaluated by:
  • mv
FALSEevaluated 565 times by 1 test
Evaluated by:
  • mv
1-592
157 if (err && err != ENOENT)
errDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • mv
FALSEevaluated 592 times by 1 test
Evaluated by:
  • mv
err != 2Description
TRUEnever evaluated
FALSEevaluated 1 time by 1 test
Evaluated by:
  • mv
0-592
158 die (EXIT_FAILURE, err, _("failed to access %s"), quoteaf (file));
never executed: ((!!sizeof (struct { _Static_assert ( 1 , "verify_expr (" "1" ", " "(error (1, err, dcgettext (((void *)0), \"failed to access %s\", 5), quotearg_style (shell_escape_always_quoting_style, file)), assume (false))" ")"); int _gl_dummy; })) ? ((error ( 1 , e...s_quoting_style, file)), (( 0 ) ? (void) 0 : __builtin_unreachable ()))) : ((error ( 1 , err, dcgettext (((void *)0), "failed to access %s" , 5) , quotearg_style (shell_escape_always_quoting_style, file)), (( 0 ) ? (void) 0 : __builtin_unreachable ()))));
0
159 return is_a_dir;
executed 593 times by 1 test: return is_a_dir;
Executed by:
  • mv
593
160}-
161-
162/* Move SOURCE onto DEST. Handles cross-file-system moves.-
163 If SOURCE is a directory, DEST must not exist.-
164 Return true if successful. */-
165-
166static bool-
167do_move (const char *source, const char *dest, const struct cp_options *x)-
168{-
169 bool copy_into_self;-
170 bool rename_succeeded;-
171 bool ok = copy (source, dest, false, x, &copy_into_self, &rename_succeeded);-
172-
173 if (ok)
okDescription
TRUEevaluated 4513 times by 1 test
Evaluated by:
  • mv
FALSEevaluated 26 times by 1 test
Evaluated by:
  • mv
26-4513
174 {-
175 char const *dir_to_remove;-
176 if (copy_into_self)
copy_into_selfDescription
TRUEevaluated 3 times by 1 test
Evaluated by:
  • mv
FALSEevaluated 4510 times by 1 test
Evaluated by:
  • mv
3-4510
177 {-
178 /* In general, when copy returns with copy_into_self set, SOURCE is-
179 the same as, or a parent of DEST. In this case we know it's a-
180 parent. It doesn't make sense to move a directory into itself, and-
181 besides in some situations doing so would give highly nonintuitive-
182 results. Run this 'mkdir b; touch a c; mv * b' in an empty-
183 directory. Here's the result of running echo $(find b -print):-
184 b b/a b/b b/b/a b/c. Notice that only file 'a' was copied-
185 into b/b. Handle this by giving a diagnostic, removing the-
186 copied-into-self directory, DEST ('b/b' in the example),-
187 and failing. */-
188-
189 dir_to_remove = NULL;-
190 ok = false;-
191 }
executed 3 times by 1 test: end of block
Executed by:
  • mv
3
192 else if (rename_succeeded)
rename_succeededDescription
TRUEevaluated 584 times by 1 test
Evaluated by:
  • mv
FALSEevaluated 3926 times by 1 test
Evaluated by:
  • mv
584-3926
193 {-
194 /* No need to remove anything. SOURCE was successfully-
195 renamed to DEST. Or the user declined to rename a file. */-
196 dir_to_remove = NULL;-
197 }
executed 584 times by 1 test: end of block
Executed by:
  • mv
584
198 else-
199 {-
200 /* This may mean SOURCE and DEST referred to different devices.-
201 It may also conceivably mean that even though they referred-
202 to the same device, rename wasn't implemented for that device.-
203-
204 E.g., (from Joel N. Weber),-
205 [...] there might someday be cases where you can't rename-
206 but you can copy where the device name is the same, especially-
207 on Hurd. Consider an ftpfs with a primitive ftp server that-
208 supports uploading, downloading and deleting, but not renaming.-
209-
210 Also, note that comparing device numbers is not a reliable-
211 check for 'can-rename'. Some systems can be set up so that-
212 files from many different physical devices all have the same-
213 st_dev field. This is a feature of some NFS mounting-
214 configurations.-
215-
216 We reach this point if SOURCE has been successfully copied-
217 to DEST. Now we have to remove SOURCE.-
218-
219 This function used to resort to copying only when rename-
220 failed and set errno to EXDEV. */-
221-
222 dir_to_remove = source;-
223 }
executed 3926 times by 1 test: end of block
Executed by:
  • mv
3926
224-
225 if (dir_to_remove != NULL)
dir_to_remove != ((void *)0)Description
TRUEevaluated 3926 times by 1 test
Evaluated by:
  • mv
FALSEevaluated 587 times by 1 test
Evaluated by:
  • mv
587-3926
226 {-
227 struct rm_options rm_options;-
228 enum RM_status status;-
229 char const *dir[2];-
230-
231 rm_option_init (&rm_options);-
232 rm_options.verbose = x->verbose;-
233 dir[0] = dir_to_remove;-
234 dir[1] = NULL;-
235-
236 status = rm ((void*) dir, &rm_options);-
237 assert (VALID_STATUS (status));-
238 if (status == RM_ERROR)
status == RM_ERRORDescription
TRUEnever evaluated
FALSEevaluated 3926 times by 1 test
Evaluated by:
  • mv
0-3926
239 ok = false;
never executed: ok = 0 ;
0
240 }
executed 3926 times by 1 test: end of block
Executed by:
  • mv
3926
241 }
executed 4513 times by 1 test: end of block
Executed by:
  • mv
4513
242-
243 return ok;
executed 4539 times by 1 test: return ok;
Executed by:
  • mv
4539
244}-
245-
246/* Move file SOURCE onto DEST. Handles the case when DEST is a directory.-
247 Treat DEST as a directory if DEST_IS_DIR.-
248 Return true if successful. */-
249-
250static bool-
251movefile (char *source, char *dest, bool dest_is_dir,-
252 const struct cp_options *x)-
253{-
254 bool ok;-
255-
256 /* This code was introduced to handle the ambiguity in the semantics-
257 of mv that is induced by the varying semantics of the rename function.-
258 Some systems (e.g., GNU/Linux) have a rename function that honors a-
259 trailing slash, while others (like Solaris 5,6,7) have a rename-
260 function that ignores a trailing slash. I believe the GNU/Linux-
261 rename semantics are POSIX and susv2 compliant. */-
262-
263 if (remove_trailing_slashes)
remove_trailing_slashesDescription
TRUEnever evaluated
FALSEevaluated 4539 times by 1 test
Evaluated by:
  • mv
0-4539
264 strip_trailing_slashes (source);
never executed: strip_trailing_slashes (source);
0
265-
266 if (dest_is_dir)
dest_is_dirDescription
TRUEevaluated 3949 times by 1 test
Evaluated by:
  • mv
FALSEevaluated 590 times by 1 test
Evaluated by:
  • mv
590-3949
267 {-
268 /* Treat DEST as a directory; build the full filename. */-
269 char const *src_basename = last_component (source);-
270 char *new_dest = file_name_concat (dest, src_basename, NULL);-
271 strip_trailing_slashes (new_dest);-
272 ok = do_move (source, new_dest, x);-
273 free (new_dest);-
274 }
executed 3949 times by 1 test: end of block
Executed by:
  • mv
3949
275 else-
276 {-
277 ok = do_move (source, dest, x);-
278 }
executed 590 times by 1 test: end of block
Executed by:
  • mv
590
279-
280 return ok;
executed 4539 times by 1 test: return ok;
Executed by:
  • mv
4539
281}-
282-
283void-
284usage (int status)-
285{-
286 if (status != EXIT_SUCCESS)
status != 0Description
TRUEevaluated 6 times by 1 test
Evaluated by:
  • mv
FALSEevaluated 22 times by 1 test
Evaluated by:
  • mv
6-22
287 emit_try_help ();
executed 6 times by 1 test: end of block
Executed by:
  • mv
6
288 else-
289 {-
290 printf (_("\-
291Usage: %s [OPTION]... [-T] SOURCE DEST\n\-
292 or: %s [OPTION]... SOURCE... DIRECTORY\n\-
293 or: %s [OPTION]... -t DIRECTORY SOURCE...\n\-
294"),-
295 program_name, program_name, program_name);-
296 fputs (_("\-
297Rename SOURCE to DEST, or move SOURCE(s) to DIRECTORY.\n\-
298"), stdout);-
299-
300 emit_mandatory_arg_note ();-
301-
302 fputs (_("\-
303 --backup[=CONTROL] make a backup of each existing destination file\-
304\n\-
305 -b like --backup but does not accept an argument\n\-
306 -f, --force do not prompt before overwriting\n\-
307 -i, --interactive prompt before overwrite\n\-
308 -n, --no-clobber do not overwrite an existing file\n\-
309If you specify more than one of -i, -f, -n, only the final one takes effect.\n\-
310"), stdout);-
311 fputs (_("\-
312 --strip-trailing-slashes remove any trailing slashes from each SOURCE\n\-
313 argument\n\-
314 -S, --suffix=SUFFIX override the usual backup suffix\n\-
315"), stdout);-
316 fputs (_("\-
317 -t, --target-directory=DIRECTORY move all SOURCE arguments into DIRECTORY\n\-
318 -T, --no-target-directory treat DEST as a normal file\n\-
319 -u, --update move only when the SOURCE file is newer\n\-
320 than the destination file or when the\n\-
321 destination file is missing\n\-
322 -v, --verbose explain what is being done\n\-
323 -Z, --context set SELinux security context of destination\n\-
324 file to default type\n\-
325"), stdout);-
326 fputs (HELP_OPTION_DESCRIPTION, stdout);-
327 fputs (VERSION_OPTION_DESCRIPTION, stdout);-
328 emit_backup_suffix_note ();-
329 emit_ancillary_info (PROGRAM_NAME);-
330 }
executed 22 times by 1 test: end of block
Executed by:
  • mv
22
331 exit (status);
executed 28 times by 1 test: exit (status);
Executed by:
  • mv
28
332}-
333-
334int-
335main (int argc, char **argv)-
336{-
337 int c;-
338 bool ok;-
339 bool make_backups = false;-
340 char const *backup_suffix = NULL;-
341 char *version_control_string = NULL;-
342 struct cp_options x;-
343 char *target_directory = NULL;-
344 bool no_target_directory = false;-
345 int n_files;-
346 char **file;-
347 bool selinux_enabled = (0 < is_selinux_enabled ());-
348-
349 initialize_main (&argc, &argv);-
350 set_program_name (argv[0]);-
351 setlocale (LC_ALL, "");-
352 bindtextdomain (PACKAGE, LOCALEDIR);-
353 textdomain (PACKAGE);-
354-
355 atexit (close_stdin);-
356-
357 cp_option_init (&x);-
358-
359 /* Try to disable the ability to unlink a directory. */-
360 priv_set_remove_linkdir ();-
361-
362 while ((c = getopt_long (argc, argv, "bfint:uvS:TZ", long_options, NULL))
(c = getopt_lo... *)0) )) != -1Description
TRUEevaluated 189 times by 1 test
Evaluated by:
  • mv
FALSEevaluated 621 times by 1 test
Evaluated by:
  • mv
189-621
363 != -1)
(c = getopt_lo... *)0) )) != -1Description
TRUEevaluated 189 times by 1 test
Evaluated by:
  • mv
FALSEevaluated 621 times by 1 test
Evaluated by:
  • mv
189-621
364 {-
365 switch (c)-
366 {-
367 case 'b':
executed 52 times by 1 test: case 'b':
Executed by:
  • mv
52
368 make_backups = true;-
369 if (optarg)
optargDescription
TRUEevaluated 44 times by 1 test
Evaluated by:
  • mv
FALSEevaluated 8 times by 1 test
Evaluated by:
  • mv
8-44
370 version_control_string = optarg;
executed 44 times by 1 test: version_control_string = optarg;
Executed by:
  • mv
44
371 break;
executed 52 times by 1 test: break;
Executed by:
  • mv
52
372 case 'f':
executed 11 times by 1 test: case 'f':
Executed by:
  • mv
11
373 x.interactive = I_ALWAYS_YES;-
374 break;
executed 11 times by 1 test: break;
Executed by:
  • mv
11
375 case 'i':
executed 13 times by 1 test: case 'i':
Executed by:
  • mv
13
376 x.interactive = I_ASK_USER;-
377 break;
executed 13 times by 1 test: break;
Executed by:
  • mv
13
378 case 'n':
executed 6 times by 1 test: case 'n':
Executed by:
  • mv
6
379 x.interactive = I_ALWAYS_NO;-
380 break;
executed 6 times by 1 test: break;
Executed by:
  • mv
6
381 case STRIP_TRAILING_SLASHES_OPTION:
executed 1 time by 1 test: case STRIP_TRAILING_SLASHES_OPTION:
Executed by:
  • mv
1
382 remove_trailing_slashes = true;-
383 break;
executed 1 time by 1 test: break;
Executed by:
  • mv
1
384 case 't':
executed 4 times by 1 test: case 't':
Executed by:
  • mv
4
385 if (target_directory)
target_directoryDescription
TRUEnever evaluated
FALSEevaluated 4 times by 1 test
Evaluated by:
  • mv
0-4
386 die (EXIT_FAILURE, 0, _("multiple target directories specified"));
never executed: ((!!sizeof (struct { _Static_assert ( 1 , "verify_expr (" "1" ", " "(error (1, 0, dcgettext (((void *)0), \"multiple target directories specified\", 5)), assume (false))" ")"); int _gl_dummy; })) ? ((error ( 1 , 0, dcgettext (((void *)0), "multiple target directories specified" , 5) ), (( 0 ) ? (void) 0 : __builtin_unreachable ()))) : ((error ( 1 , 0, dcgettext (((void *)0), "multiple target directories specified" , 5) ), (( 0 ) ? (void) 0 : __builtin_unreachable ()))));
0
387 else-
388 {-
389 struct stat st;-
390 if (stat (optarg, &st) != 0)
stat (optarg, &st) != 0Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • mv
FALSEevaluated 2 times by 1 test
Evaluated by:
  • mv
2
391 die (EXIT_FAILURE, errno, _("failed to access %s"),
executed 2 times by 1 test: ((!!sizeof (struct { _Static_assert ( 1 , "verify_expr (" "1" ", " "(error (1, (*__errno_location ()), dcgettext (((void *)0), \"failed to access %s\", 5), quotearg_style (shell_escape_always_quoting_style, optarg)), assume (false))" ")"); int _gl_dummy; ..., (( 0 ) ? (void) 0 : __builtin_unreachable ()))) : ((error ( 1 , (*__errno_location ()) , dcgettext (((void *)0), "failed to access %s" , 5) , quotearg_style (shell_escape_always_quoting_style, optarg)), (( 0 ) ? (void) 0 : __builtin_unreachable ())))) ;
Executed by:
  • mv
2
392 quoteaf (optarg));
executed 2 times by 1 test: ((!!sizeof (struct { _Static_assert ( 1 , "verify_expr (" "1" ", " "(error (1, (*__errno_location ()), dcgettext (((void *)0), \"failed to access %s\", 5), quotearg_style (shell_escape_always_quoting_style, optarg)), assume (false))" ")"); int _gl_dummy; ..., (( 0 ) ? (void) 0 : __builtin_unreachable ()))) : ((error ( 1 , (*__errno_location ()) , dcgettext (((void *)0), "failed to access %s" , 5) , quotearg_style (shell_escape_always_quoting_style, optarg)), (( 0 ) ? (void) 0 : __builtin_unreachable ())))) ;
Executed by:
  • mv
2
393 if (! S_ISDIR (st.st_mode))
! (((( st.st_m... == (0040000))Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • mv
FALSEevaluated 1 time by 1 test
Evaluated by:
  • mv
1
394 die (EXIT_FAILURE, 0, _("target %s is not a directory"),
executed 1 time by 1 test: ((!!sizeof (struct { _Static_assert ( 1 , "verify_expr (" "1" ", " "(error (1, 0, dcgettext (((void *)0), \"target %s is not a directory\", 5), quotearg_style (shell_escape_always_quoting_style, optarg)), assume (false))" ")"); int _gl_dummy; })) ? ((erro...yle, optarg)), (( 0 ) ? (void) 0 : __builtin_unreachable ()))) : ((error ( 1 , 0, dcgettext (((void *)0), "target %s is not a directory" , 5) , quotearg_style (shell_escape_always_quoting_style, optarg)), (( 0 ) ? (void) 0 : __builtin_unreachable ())))) ;
Executed by:
  • mv
1
395 quoteaf (optarg));
executed 1 time by 1 test: ((!!sizeof (struct { _Static_assert ( 1 , "verify_expr (" "1" ", " "(error (1, 0, dcgettext (((void *)0), \"target %s is not a directory\", 5), quotearg_style (shell_escape_always_quoting_style, optarg)), assume (false))" ")"); int _gl_dummy; })) ? ((erro...yle, optarg)), (( 0 ) ? (void) 0 : __builtin_unreachable ()))) : ((error ( 1 , 0, dcgettext (((void *)0), "target %s is not a directory" , 5) , quotearg_style (shell_escape_always_quoting_style, optarg)), (( 0 ) ? (void) 0 : __builtin_unreachable ())))) ;
Executed by:
  • mv
1
396 }
executed 1 time by 1 test: end of block
Executed by:
  • mv
1
397 target_directory = optarg;-
398 break;
executed 1 time by 1 test: break;
Executed by:
  • mv
1
399 case 'T':
executed 8 times by 1 test: case 'T':
Executed by:
  • mv
8
400 no_target_directory = true;-
401 break;
executed 8 times by 1 test: break;
Executed by:
  • mv
8
402 case 'u':
executed 6 times by 1 test: case 'u':
Executed by:
  • mv
6
403 x.update = true;-
404 break;
executed 6 times by 1 test: break;
Executed by:
  • mv
6
405 case 'v':
executed 10 times by 1 test: case 'v':
Executed by:
  • mv
10
406 x.verbose = true;-
407 break;
executed 10 times by 1 test: break;
Executed by:
  • mv
10
408 case 'S':
executed 3 times by 1 test: case 'S':
Executed by:
  • mv
3
409 make_backups = true;-
410 backup_suffix = optarg;-
411 break;
executed 3 times by 1 test: break;
Executed by:
  • mv
3
412 case 'Z':
executed 2 times by 1 test: case 'Z':
Executed by:
  • mv
2
413 /* As a performance enhancement, don't even bother trying-
414 to "restorecon" when not on an selinux-enabled kernel. */-
415 if (selinux_enabled)
selinux_enabledDescription
TRUEnever evaluated
FALSEevaluated 2 times by 1 test
Evaluated by:
  • mv
0-2
416 {-
417 x.preserve_security_context = false;-
418 x.set_security_context = true;-
419 }
never executed: end of block
0
420 break;
executed 2 times by 1 test: break;
Executed by:
  • mv
2
421 case_GETOPT_HELP_CHAR;
never executed: break;
executed 22 times by 1 test: case GETOPT_HELP_CHAR:
Executed by:
  • mv
0-22
422 case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS);
executed 48 times by 1 test: exit ( 0 );
Executed by:
  • mv
never executed: break;
executed 48 times by 1 test: case GETOPT_VERSION_CHAR:
Executed by:
  • mv
0-48
423 default:
executed 3 times by 1 test: default:
Executed by:
  • mv
3
424 usage (EXIT_FAILURE);-
425 }
never executed: end of block
0
426 }-
427-
428 n_files = argc - optind;-
429 file = argv + optind;-
430-
431 if (n_files <= !target_directory)
n_files <= !target_directoryDescription
TRUEevaluated 2 times by 1 test
Evaluated by:
  • mv
FALSEevaluated 619 times by 1 test
Evaluated by:
  • mv
2-619
432 {-
433 if (n_files <= 0)
n_files <= 0Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • mv
FALSEevaluated 1 time by 1 test
Evaluated by:
  • mv
1
434 error (0, 0, _("missing file operand"));
executed 1 time by 1 test: error (0, 0, dcgettext (((void *)0), "missing file operand" , 5) );
Executed by:
  • mv
1
435 else-
436 error (0, 0, _("missing destination file operand after %s"),
executed 1 time by 1 test: error (0, 0, dcgettext (((void *)0), "missing destination file operand after %s" , 5) , quotearg_style (shell_escape_always_quoting_style, file[0]));
Executed by:
  • mv
1
437 quoteaf (file[0]));
executed 1 time by 1 test: error (0, 0, dcgettext (((void *)0), "missing destination file operand after %s" , 5) , quotearg_style (shell_escape_always_quoting_style, file[0]));
Executed by:
  • mv
1
438 usage (EXIT_FAILURE);-
439 }
never executed: end of block
0
440-
441 if (no_target_directory)
no_target_directoryDescription
TRUEevaluated 6 times by 1 test
Evaluated by:
  • mv
FALSEevaluated 613 times by 1 test
Evaluated by:
  • mv
6-613
442 {-
443 if (target_directory)
target_directoryDescription
TRUEnever evaluated
FALSEevaluated 6 times by 1 test
Evaluated by:
  • mv
0-6
444 die (EXIT_FAILURE, 0,
never executed: ((!!sizeof (struct { _Static_assert ( 1 , "verify_expr (" "1" ", " "(error (1, 0, dcgettext (((void *)0), \"cannot combine --target-directory (-t) \" \"and --no-target-directory (-T)\", 5)), assume (false))" ")"); int _gl_dummy; })) ? ((error ( 1 , 0, dcg...target-directory (-T)" , 5) ), (( 0 ) ? (void) 0 : __builtin_unreachable ()))) : ((error ( 1 , 0, dcgettext (((void *)0), "cannot combine --target-directory (-t) " "and --no-target-directory (-T)" , 5) ), (( 0 ) ? (void) 0 : __builtin_unreachable ())))) ;
0
445 _("cannot combine --target-directory (-t) "
never executed: ((!!sizeof (struct { _Static_assert ( 1 , "verify_expr (" "1" ", " "(error (1, 0, dcgettext (((void *)0), \"cannot combine --target-directory (-t) \" \"and --no-target-directory (-T)\", 5)), assume (false))" ")"); int _gl_dummy; })) ? ((error ( 1 , 0, dcg...target-directory (-T)" , 5) ), (( 0 ) ? (void) 0 : __builtin_unreachable ()))) : ((error ( 1 , 0, dcgettext (((void *)0), "cannot combine --target-directory (-t) " "and --no-target-directory (-T)" , 5) ), (( 0 ) ? (void) 0 : __builtin_unreachable ())))) ;
0
446 "and --no-target-directory (-T)"));
never executed: ((!!sizeof (struct { _Static_assert ( 1 , "verify_expr (" "1" ", " "(error (1, 0, dcgettext (((void *)0), \"cannot combine --target-directory (-t) \" \"and --no-target-directory (-T)\", 5)), assume (false))" ")"); int _gl_dummy; })) ? ((error ( 1 , 0, dcg...target-directory (-T)" , 5) ), (( 0 ) ? (void) 0 : __builtin_unreachable ()))) : ((error ( 1 , 0, dcgettext (((void *)0), "cannot combine --target-directory (-t) " "and --no-target-directory (-T)" , 5) ), (( 0 ) ? (void) 0 : __builtin_unreachable ())))) ;
0
447 if (2 < n_files)
2 < n_filesDescription
TRUEnever evaluated
FALSEevaluated 6 times by 1 test
Evaluated by:
  • mv
0-6
448 {-
449 error (0, 0, _("extra operand %s"), quoteaf (file[2]));-
450 usage (EXIT_FAILURE);-
451 }
never executed: end of block
0
452 }
executed 6 times by 1 test: end of block
Executed by:
  • mv
6
453 else if (!target_directory)
!target_directoryDescription
TRUEevaluated 613 times by 1 test
Evaluated by:
  • mv
FALSEnever evaluated
0-613
454 {-
455 assert (2 <= n_files);-
456 if (n_files == 2)
n_files == 2Description
TRUEevaluated 596 times by 1 test
Evaluated by:
  • mv
FALSEevaluated 17 times by 1 test
Evaluated by:
  • mv
17-596
457 x.rename_errno = (renameat2 (AT_FDCWD, file[0], AT_FDCWD, file[1],
executed 596 times by 1 test: x.rename_errno = (renameat2 ( -100 , file[0], -100 , file[1], (1 << 0) ) ? (*__errno_location ()) : 0);
Executed by:
  • mv
renameat2 ( -1...1], (1 << 0) )Description
TRUEevaluated 576 times by 1 test
Evaluated by:
  • mv
FALSEevaluated 20 times by 1 test
Evaluated by:
  • mv
20-596
458 RENAME_NOREPLACE)
executed 596 times by 1 test: x.rename_errno = (renameat2 ( -100 , file[0], -100 , file[1], (1 << 0) ) ? (*__errno_location ()) : 0);
Executed by:
  • mv
renameat2 ( -1...1], (1 << 0) )Description
TRUEevaluated 576 times by 1 test
Evaluated by:
  • mv
FALSEevaluated 20 times by 1 test
Evaluated by:
  • mv
20-596
459 ? errno : 0);
executed 596 times by 1 test: x.rename_errno = (renameat2 ( -100 , file[0], -100 , file[1], (1 << 0) ) ? (*__errno_location ()) : 0);
Executed by:
  • mv
596
460 if (x.rename_errno != 0 && target_directory_operand (file[n_files - 1]))
x.rename_errno != 0Description
TRUEevaluated 593 times by 1 test
Evaluated by:
  • mv
FALSEevaluated 20 times by 1 test
Evaluated by:
  • mv
target_directo...[n_files - 1])Description
TRUEevaluated 27 times by 1 test
Evaluated by:
  • mv
FALSEevaluated 566 times by 1 test
Evaluated by:
  • mv
20-593
461 {-
462 x.rename_errno = -1;-
463 target_directory = file[--n_files];-
464 }
executed 27 times by 1 test: end of block
Executed by:
  • mv
27
465 else if (2 < n_files)
2 < n_filesDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • mv
FALSEevaluated 585 times by 1 test
Evaluated by:
  • mv
1-585
466 die (EXIT_FAILURE, 0, _("target %s is not a directory"),
executed 1 time by 1 test: ((!!sizeof (struct { _Static_assert ( 1 , "verify_expr (" "1" ", " "(error (1, 0, dcgettext (((void *)0), \"target %s is not a directory\", 5), quotearg_style (shell_escape_always_quoting_style, file[n_files - 1])), assume (false))" ")"); int _gl_dummy; }...)), (( 0 ) ? (void) 0 : __builtin_unreachable ()))) : ((error ( 1 , 0, dcgettext (((void *)0), "target %s is not a directory" , 5) , quotearg_style (shell_escape_always_quoting_style, file[n_files - 1])), (( 0 ) ? (void) 0 : __builtin_unreachable ())))) ;
Executed by:
  • mv
1
467 quoteaf (file[n_files - 1]));
executed 1 time by 1 test: ((!!sizeof (struct { _Static_assert ( 1 , "verify_expr (" "1" ", " "(error (1, 0, dcgettext (((void *)0), \"target %s is not a directory\", 5), quotearg_style (shell_escape_always_quoting_style, file[n_files - 1])), assume (false))" ")"); int _gl_dummy; }...)), (( 0 ) ? (void) 0 : __builtin_unreachable ()))) : ((error ( 1 , 0, dcgettext (((void *)0), "target %s is not a directory" , 5) , quotearg_style (shell_escape_always_quoting_style, file[n_files - 1])), (( 0 ) ? (void) 0 : __builtin_unreachable ())))) ;
Executed by:
  • mv
1
468 }
executed 612 times by 1 test: end of block
Executed by:
  • mv
612
469-
470 if (x.interactive == I_ALWAYS_NO)
x.interactive == I_ALWAYS_NODescription
TRUEevaluated 4 times by 1 test
Evaluated by:
  • mv
FALSEevaluated 614 times by 1 test
Evaluated by:
  • mv
4-614
471 x.update = false;
executed 4 times by 1 test: x.update = 0 ;
Executed by:
  • mv
4
472-
473 if (make_backups && x.interactive == I_ALWAYS_NO)
make_backupsDescription
TRUEevaluated 50 times by 1 test
Evaluated by:
  • mv
FALSEevaluated 568 times by 1 test
Evaluated by:
  • mv
x.interactive == I_ALWAYS_NODescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • mv
FALSEevaluated 49 times by 1 test
Evaluated by:
  • mv
1-568
474 {-
475 error (0, 0,-
476 _("options --backup and --no-clobber are mutually exclusive"));-
477 usage (EXIT_FAILURE);-
478 }
never executed: end of block
0
479-
480 x.backup_type = (make_backups
make_backupsDescription
TRUEevaluated 49 times by 1 test
Evaluated by:
  • mv
FALSEevaluated 568 times by 1 test
Evaluated by:
  • mv
49-568
481 ? xget_version (_("backup type"),-
482 version_control_string)-
483 : no_backups);-
484 set_simple_backup_suffix (backup_suffix);-
485-
486 hash_init ();-
487-
488 if (target_directory)
target_directoryDescription
TRUEevaluated 27 times by 1 test
Evaluated by:
  • mv
FALSEevaluated 590 times by 1 test
Evaluated by:
  • mv
27-590
489 {-
490 /* Initialize the hash table only if we'll need it.-
491 The problem it is used to detect can arise only if there are-
492 two or more files to move. */-
493 if (2 <= n_files)
2 <= n_filesDescription
TRUEevaluated 16 times by 1 test
Evaluated by:
  • mv
FALSEevaluated 11 times by 1 test
Evaluated by:
  • mv
11-16
494 dest_info_init (&x);
executed 16 times by 1 test: dest_info_init (&x);
Executed by:
  • mv
16
495-
496 ok = true;-
497 for (int i = 0; i < n_files; ++i)
i < n_filesDescription
TRUEevaluated 3949 times by 1 test
Evaluated by:
  • mv
FALSEevaluated 27 times by 1 test
Evaluated by:
  • mv
27-3949
498 {-
499 x.last_file = i + 1 == n_files;-
500 ok &= movefile (file[i], target_directory, true, &x);-
501 }
executed 3949 times by 1 test: end of block
Executed by:
  • mv
3949
502 }
executed 27 times by 1 test: end of block
Executed by:
  • mv
27
503 else-
504 {-
505 x.last_file = true;-
506 ok = movefile (file[0], file[1], false, &x);-
507 }
executed 590 times by 1 test: end of block
Executed by:
  • mv
590
508-
509 return ok ? EXIT_SUCCESS : EXIT_FAILURE;
executed 617 times by 1 test: return ok ? 0 : 1 ;
Executed by:
  • mv
617
510}-
Source codeSwitch to Preprocessed file

Generated by Squish Coco 4.1.2