extract.c 37 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441
  1. /* Extract files from a tar archive.
  2. Copyright (C) 1988, 1992, 1993, 1994, 1996, 1997, 1998, 1999, 2000,
  3. 2001, 2003, 2004, 2005, 2006, 2007, 2010 Free Software Foundation, Inc.
  4. Written by John Gilmore, on 1985-11-19.
  5. This program is free software; you can redistribute it and/or modify it
  6. under the terms of the GNU General Public License as published by the
  7. Free Software Foundation; either version 3, or (at your option) any later
  8. version.
  9. This program is distributed in the hope that it will be useful, but
  10. WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
  12. Public License for more details.
  13. You should have received a copy of the GNU General Public License along
  14. with this program; if not, write to the Free Software Foundation, Inc.,
  15. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
  16. #include <system.h>
  17. #include <quotearg.h>
  18. #include <utimens.h>
  19. #include <errno.h>
  20. #include <xgetcwd.h>
  21. #include <priv-set.h>
  22. #include "common.h"
  23. static bool we_are_root; /* true if our effective uid == 0 */
  24. static mode_t newdir_umask; /* umask when creating new directories */
  25. static mode_t current_umask; /* current umask (which is set to 0 if -p) */
  26. /* Status of the permissions of a file that we are extracting. */
  27. enum permstatus
  28. {
  29. /* This file may have existed already; its permissions are unknown. */
  30. UNKNOWN_PERMSTATUS,
  31. /* This file was created using the permissions from the archive,
  32. except with S_IRWXG | S_IRWXO masked out if 0 < same_owner_option. */
  33. ARCHIVED_PERMSTATUS,
  34. /* This is an intermediate directory; the archive did not specify
  35. its permissions. */
  36. INTERDIR_PERMSTATUS
  37. };
  38. /* List of directories whose statuses we need to extract after we've
  39. finished extracting their subsidiary files. If you consider each
  40. contiguous subsequence of elements of the form [D]?[^D]*, where [D]
  41. represents an element where AFTER_LINKS is nonzero and [^D]
  42. represents an element where AFTER_LINKS is zero, then the head
  43. of the subsequence has the longest name, and each non-head element
  44. in the prefix is an ancestor (in the directory hierarchy) of the
  45. preceding element. */
  46. struct delayed_set_stat
  47. {
  48. struct delayed_set_stat *next;
  49. dev_t dev;
  50. ino_t ino;
  51. mode_t mode;
  52. uid_t uid;
  53. gid_t gid;
  54. struct timespec atime;
  55. struct timespec mtime;
  56. size_t file_name_len;
  57. mode_t invert_permissions;
  58. enum permstatus permstatus;
  59. bool after_links;
  60. char file_name[1];
  61. };
  62. static struct delayed_set_stat *delayed_set_stat_head;
  63. /* List of links whose creation we have delayed. */
  64. struct delayed_link
  65. {
  66. /* The next delayed link in the list. */
  67. struct delayed_link *next;
  68. /* The device, inode number and last-modified time of the placeholder. */
  69. dev_t dev;
  70. ino_t ino;
  71. struct timespec mtime;
  72. /* True if the link is symbolic. */
  73. bool is_symlink;
  74. /* The desired owner and group of the link, if it is a symlink. */
  75. uid_t uid;
  76. gid_t gid;
  77. /* A list of sources for this link. The sources are all to be
  78. hard-linked together. */
  79. struct string_list *sources;
  80. /* The desired target of the desired link. */
  81. char target[1];
  82. };
  83. static struct delayed_link *delayed_link_head;
  84. struct string_list
  85. {
  86. struct string_list *next;
  87. char string[1];
  88. };
  89. /* Set up to extract files. */
  90. void
  91. extr_init (void)
  92. {
  93. we_are_root = geteuid () == 0;
  94. same_permissions_option += we_are_root;
  95. same_owner_option += we_are_root;
  96. /* Option -p clears the kernel umask, so it does not affect proper
  97. restoration of file permissions. New intermediate directories will
  98. comply with umask at start of program. */
  99. newdir_umask = umask (0);
  100. if (0 < same_permissions_option)
  101. current_umask = 0;
  102. else
  103. {
  104. umask (newdir_umask); /* restore the kernel umask */
  105. current_umask = newdir_umask;
  106. }
  107. }
  108. /* If restoring permissions, restore the mode for FILE_NAME from
  109. information given in *STAT_INFO (where *CUR_INFO gives
  110. the current status if CUR_INFO is nonzero); otherwise invert the
  111. INVERT_PERMISSIONS bits from the file's current permissions.
  112. PERMSTATUS specifies the status of the file's permissions.
  113. TYPEFLAG specifies the type of the file. */
  114. static void
  115. set_mode (char const *file_name,
  116. struct stat const *stat_info,
  117. struct stat const *cur_info,
  118. mode_t invert_permissions, enum permstatus permstatus,
  119. char typeflag)
  120. {
  121. mode_t mode;
  122. bool failed;
  123. if (0 < same_permissions_option
  124. && permstatus != INTERDIR_PERMSTATUS)
  125. {
  126. mode = stat_info->st_mode;
  127. /* If we created the file and it has a mode that we set already
  128. with O_CREAT, then its mode is often set correctly already.
  129. But if we are changing ownership, the mode's group and and
  130. other permission bits were omitted originally, so it's less
  131. likely that the mode is OK now. Also, on many hosts, some
  132. directories inherit the setgid bits from their parents, so we
  133. we must set directories' modes explicitly. */
  134. if ((permstatus == ARCHIVED_PERMSTATUS
  135. && ! (mode & ~ (0 < same_owner_option ? S_IRWXU : MODE_RWX)))
  136. && typeflag != DIRTYPE
  137. && typeflag != GNUTYPE_DUMPDIR)
  138. return;
  139. }
  140. else if (! invert_permissions)
  141. return;
  142. else
  143. {
  144. /* We must inspect a directory's current permissions, since the
  145. directory may have inherited its setgid bit from its parent.
  146. INVERT_PERMISSIONS happens to be nonzero only for directories
  147. that we created, so there's no point optimizing this code for
  148. other cases. */
  149. struct stat st;
  150. if (! cur_info)
  151. {
  152. if (stat (file_name, &st) != 0)
  153. {
  154. stat_error (file_name);
  155. return;
  156. }
  157. cur_info = &st;
  158. }
  159. mode = cur_info->st_mode ^ invert_permissions;
  160. }
  161. failed = chmod (file_name, mode) != 0;
  162. if (failed && errno == EPERM)
  163. {
  164. /* On Solaris, chmod may fail if we don't have PRIV_ALL. */
  165. if (priv_set_restore_linkdir () == 0)
  166. {
  167. failed = chmod (file_name, mode) != 0;
  168. priv_set_remove_linkdir ();
  169. }
  170. }
  171. if (failed)
  172. chmod_error_details (file_name, mode);
  173. }
  174. /* Check time after successfully setting FILE_NAME's time stamp to T. */
  175. static void
  176. check_time (char const *file_name, struct timespec t)
  177. {
  178. if (t.tv_sec <= 0)
  179. WARNOPT (WARN_TIMESTAMP,
  180. (0, 0, _("%s: implausibly old time stamp %s"),
  181. file_name, tartime (t, true)));
  182. else if (timespec_cmp (volume_start_time, t) < 0)
  183. {
  184. struct timespec now;
  185. gettime (&now);
  186. if (timespec_cmp (now, t) < 0)
  187. {
  188. char buf[TIMESPEC_STRSIZE_BOUND];
  189. struct timespec diff;
  190. diff.tv_sec = t.tv_sec - now.tv_sec;
  191. diff.tv_nsec = t.tv_nsec - now.tv_nsec;
  192. if (diff.tv_nsec < 0)
  193. {
  194. diff.tv_nsec += BILLION;
  195. diff.tv_sec--;
  196. }
  197. WARNOPT (WARN_TIMESTAMP,
  198. (0, 0, _("%s: time stamp %s is %s s in the future"),
  199. file_name, tartime (t, true), code_timespec (diff, buf)));
  200. }
  201. }
  202. }
  203. /* Restore stat attributes (owner, group, mode and times) for
  204. FILE_NAME, using information given in *ST.
  205. If CUR_INFO is nonzero, *CUR_INFO is the
  206. file's current status.
  207. If not restoring permissions, invert the
  208. INVERT_PERMISSIONS bits from the file's current permissions.
  209. PERMSTATUS specifies the status of the file's permissions.
  210. TYPEFLAG specifies the type of the file. */
  211. /* FIXME: About proper restoration of symbolic link attributes, we still do
  212. not have it right. Pretesters' reports tell us we need further study and
  213. probably more configuration. For now, just use lchown if it exists, and
  214. punt for the rest. Sigh! */
  215. static void
  216. set_stat (char const *file_name,
  217. struct tar_stat_info const *st,
  218. struct stat const *cur_info,
  219. mode_t invert_permissions, enum permstatus permstatus,
  220. char typeflag)
  221. {
  222. if (typeflag != SYMTYPE)
  223. {
  224. /* We do the utime before the chmod because some versions of utime are
  225. broken and trash the modes of the file. */
  226. if (! touch_option && permstatus != INTERDIR_PERMSTATUS)
  227. {
  228. /* We set the accessed time to `now', which is really the time we
  229. started extracting files, unless incremental_option is used, in
  230. which case .st_atime is used. */
  231. /* FIXME: incremental_option should set ctime too, but how? */
  232. struct timespec ts[2];
  233. if (incremental_option)
  234. ts[0] = st->atime;
  235. else
  236. ts[0] = start_time;
  237. ts[1] = st->mtime;
  238. if (utimens (file_name, ts) != 0)
  239. utime_error (file_name);
  240. else
  241. {
  242. check_time (file_name, ts[0]);
  243. check_time (file_name, ts[1]);
  244. }
  245. }
  246. /* Some systems allow non-root users to give files away. Once this
  247. done, it is not possible anymore to change file permissions.
  248. However, setting file permissions now would be incorrect, since
  249. they would apply to the wrong user, and there would be a race
  250. condition. So, don't use systems that allow non-root users to
  251. give files away. */
  252. }
  253. if (0 < same_owner_option && permstatus != INTERDIR_PERMSTATUS)
  254. {
  255. /* When lchown exists, it should be used to change the attributes of
  256. the symbolic link itself. In this case, a mere chown would change
  257. the attributes of the file the symbolic link is pointing to, and
  258. should be avoided. */
  259. int chown_result = 1;
  260. if (typeflag == SYMTYPE)
  261. {
  262. #if HAVE_LCHOWN
  263. chown_result = lchown (file_name, st->stat.st_uid, st->stat.st_gid);
  264. #endif
  265. }
  266. else
  267. {
  268. chown_result = chown (file_name, st->stat.st_uid, st->stat.st_gid);
  269. }
  270. if (chown_result == 0)
  271. {
  272. /* Changing the owner can flip st_mode bits in some cases, so
  273. ignore cur_info if it might be obsolete now. */
  274. if (cur_info
  275. && cur_info->st_mode & S_IXUGO
  276. && cur_info->st_mode & (S_ISUID | S_ISGID))
  277. cur_info = NULL;
  278. }
  279. else if (chown_result < 0)
  280. chown_error_details (file_name,
  281. st->stat.st_uid, st->stat.st_gid);
  282. }
  283. if (typeflag != SYMTYPE)
  284. set_mode (file_name, &st->stat, cur_info,
  285. invert_permissions, permstatus, typeflag);
  286. }
  287. /* Remember to restore stat attributes (owner, group, mode and times)
  288. for the directory FILE_NAME, using information given in *ST,
  289. once we stop extracting files into that directory.
  290. If not restoring permissions, remember to invert the
  291. INVERT_PERMISSIONS bits from the file's current permissions.
  292. PERMSTATUS specifies the status of the file's permissions.
  293. NOTICE: this works only if the archive has usual member order, i.e.
  294. directory, then the files in that directory. Incremental archive have
  295. somewhat reversed order: first go subdirectories, then all other
  296. members. To help cope with this case the variable
  297. delay_directory_restore_option is set by prepare_to_extract.
  298. If an archive was explicitely created so that its member order is
  299. reversed, some directory timestamps can be restored incorrectly,
  300. e.g.:
  301. tar --no-recursion -cf archive dir dir/file1 foo dir/file2
  302. */
  303. static void
  304. delay_set_stat (char const *file_name, struct tar_stat_info const *st,
  305. mode_t invert_permissions, enum permstatus permstatus)
  306. {
  307. size_t file_name_len = strlen (file_name);
  308. struct delayed_set_stat *data =
  309. xmalloc (offsetof (struct delayed_set_stat, file_name)
  310. + file_name_len + 1);
  311. data->next = delayed_set_stat_head;
  312. data->dev = st->stat.st_dev;
  313. data->ino = st->stat.st_ino;
  314. data->mode = st->stat.st_mode;
  315. data->uid = st->stat.st_uid;
  316. data->gid = st->stat.st_gid;
  317. data->atime = st->atime;
  318. data->mtime = st->mtime;
  319. data->file_name_len = file_name_len;
  320. data->invert_permissions = invert_permissions;
  321. data->permstatus = permstatus;
  322. data->after_links = 0;
  323. strcpy (data->file_name, file_name);
  324. delayed_set_stat_head = data;
  325. }
  326. /* Update the delayed_set_stat info for an intermediate directory
  327. created within the file name of DIR. The intermediate directory turned
  328. out to be the same as this directory, e.g. due to ".." or symbolic
  329. links. *DIR_STAT_INFO is the status of the directory. */
  330. static void
  331. repair_delayed_set_stat (char const *dir,
  332. struct stat const *dir_stat_info)
  333. {
  334. struct delayed_set_stat *data;
  335. for (data = delayed_set_stat_head; data; data = data->next)
  336. {
  337. struct stat st;
  338. if (stat (data->file_name, &st) != 0)
  339. {
  340. stat_error (data->file_name);
  341. return;
  342. }
  343. if (st.st_dev == dir_stat_info->st_dev
  344. && st.st_ino == dir_stat_info->st_ino)
  345. {
  346. data->dev = current_stat_info.stat.st_dev;
  347. data->ino = current_stat_info.stat.st_ino;
  348. data->mode = current_stat_info.stat.st_mode;
  349. data->uid = current_stat_info.stat.st_uid;
  350. data->gid = current_stat_info.stat.st_gid;
  351. data->atime = current_stat_info.atime;
  352. data->mtime = current_stat_info.mtime;
  353. data->invert_permissions =
  354. ((current_stat_info.stat.st_mode ^ st.st_mode)
  355. & MODE_RWX & ~ current_umask);
  356. data->permstatus = ARCHIVED_PERMSTATUS;
  357. return;
  358. }
  359. }
  360. ERROR ((0, 0, _("%s: Unexpected inconsistency when making directory"),
  361. quotearg_colon (dir)));
  362. }
  363. /* After a file/link/directory creation has failed, see if
  364. it's because some required directory was not present, and if so,
  365. create all required directories. Return non-zero if a directory
  366. was created. */
  367. static int
  368. make_directories (char *file_name)
  369. {
  370. char *cursor0 = file_name + FILE_SYSTEM_PREFIX_LEN (file_name);
  371. char *cursor; /* points into the file name */
  372. int did_something = 0; /* did we do anything yet? */
  373. int mode;
  374. int invert_permissions;
  375. int status;
  376. for (cursor = cursor0; *cursor; cursor++)
  377. {
  378. if (! ISSLASH (*cursor))
  379. continue;
  380. /* Avoid mkdir of empty string, if leading or double '/'. */
  381. if (cursor == cursor0 || ISSLASH (cursor[-1]))
  382. continue;
  383. /* Avoid mkdir where last part of file name is "." or "..". */
  384. if (cursor[-1] == '.'
  385. && (cursor == cursor0 + 1 || ISSLASH (cursor[-2])
  386. || (cursor[-2] == '.'
  387. && (cursor == cursor0 + 2 || ISSLASH (cursor[-3])))))
  388. continue;
  389. *cursor = '\0'; /* truncate the name there */
  390. mode = MODE_RWX & ~ newdir_umask;
  391. invert_permissions = we_are_root ? 0 : MODE_WXUSR & ~ mode;
  392. status = mkdir (file_name, mode ^ invert_permissions);
  393. if (status == 0)
  394. {
  395. /* Create a struct delayed_set_stat even if
  396. invert_permissions is zero, because
  397. repair_delayed_set_stat may need to update the struct. */
  398. delay_set_stat (file_name,
  399. &current_stat_info,
  400. invert_permissions, INTERDIR_PERMSTATUS);
  401. print_for_mkdir (file_name, cursor - file_name, mode);
  402. did_something = 1;
  403. *cursor = '/';
  404. continue;
  405. }
  406. *cursor = '/';
  407. if (errno == EEXIST)
  408. continue; /* Directory already exists. */
  409. else if ((errno == ENOSYS /* Automounted dirs on Solaris return
  410. this. Reported by Warren Hyde
  411. <Warren.Hyde@motorola.com> */
  412. || ERRNO_IS_EACCES) /* Turbo C mkdir gives a funny errno. */
  413. && access (file_name, W_OK) == 0)
  414. continue;
  415. /* Some other error in the mkdir. We return to the caller. */
  416. break;
  417. }
  418. return did_something; /* tell them to retry if we made one */
  419. }
  420. static bool
  421. file_newer_p (const char *file_name, struct tar_stat_info *tar_stat)
  422. {
  423. struct stat st;
  424. if (stat (file_name, &st))
  425. {
  426. if (errno != ENOENT)
  427. {
  428. stat_warn (file_name);
  429. /* Be on the safe side: if the file does exist assume it is newer */
  430. return true;
  431. }
  432. return false;
  433. }
  434. if (!S_ISDIR (st.st_mode)
  435. && tar_timespec_cmp (tar_stat->mtime, get_stat_mtime (&st)) <= 0)
  436. {
  437. return true;
  438. }
  439. return false;
  440. }
  441. #define RECOVER_NO 0
  442. #define RECOVER_OK 1
  443. #define RECOVER_SKIP 2
  444. /* Attempt repairing what went wrong with the extraction. Delete an
  445. already existing file or create missing intermediate directories.
  446. Return RECOVER_OK if we somewhat increased our chances at a successful
  447. extraction, RECOVER_NO if there are no chances, and RECOVER_SKIP if the
  448. caller should skip extraction of that member. The value of errno is
  449. properly restored on returning RECOVER_NO. */
  450. static int
  451. maybe_recoverable (char *file_name, int *interdir_made)
  452. {
  453. int e = errno;
  454. if (*interdir_made)
  455. return RECOVER_NO;
  456. switch (errno)
  457. {
  458. case EEXIST:
  459. /* Remove an old file, if the options allow this. */
  460. switch (old_files_option)
  461. {
  462. case KEEP_OLD_FILES:
  463. return RECOVER_SKIP;
  464. case KEEP_NEWER_FILES:
  465. if (file_newer_p (file_name, &current_stat_info))
  466. {
  467. errno = e;
  468. return RECOVER_NO;
  469. }
  470. /* FALL THROUGH */
  471. case DEFAULT_OLD_FILES:
  472. case NO_OVERWRITE_DIR_OLD_FILES:
  473. case OVERWRITE_OLD_FILES:
  474. {
  475. int r = remove_any_file (file_name, ORDINARY_REMOVE_OPTION);
  476. errno = EEXIST;
  477. return r > 0 ? RECOVER_OK : RECOVER_NO;
  478. }
  479. case UNLINK_FIRST_OLD_FILES:
  480. break;
  481. }
  482. case ENOENT:
  483. /* Attempt creating missing intermediate directories. */
  484. if (! make_directories (file_name))
  485. {
  486. errno = ENOENT;
  487. return RECOVER_NO;
  488. }
  489. *interdir_made = 1;
  490. return RECOVER_OK;
  491. default:
  492. /* Just say we can't do anything about it... */
  493. return RECOVER_NO;
  494. }
  495. }
  496. /* Fix the statuses of all directories whose statuses need fixing, and
  497. which are not ancestors of FILE_NAME. If AFTER_LINKS is
  498. nonzero, do this for all such directories; otherwise, stop at the
  499. first directory that is marked to be fixed up only after delayed
  500. links are applied. */
  501. static void
  502. apply_nonancestor_delayed_set_stat (char const *file_name, bool after_links)
  503. {
  504. size_t file_name_len = strlen (file_name);
  505. bool check_for_renamed_directories = 0;
  506. while (delayed_set_stat_head)
  507. {
  508. struct delayed_set_stat *data = delayed_set_stat_head;
  509. bool skip_this_one = 0;
  510. struct stat st;
  511. struct stat const *cur_info = 0;
  512. check_for_renamed_directories |= data->after_links;
  513. if (after_links < data->after_links
  514. || (data->file_name_len < file_name_len
  515. && file_name[data->file_name_len]
  516. && (ISSLASH (file_name[data->file_name_len])
  517. || ISSLASH (file_name[data->file_name_len - 1]))
  518. && memcmp (file_name, data->file_name, data->file_name_len) == 0))
  519. break;
  520. if (check_for_renamed_directories)
  521. {
  522. cur_info = &st;
  523. if (stat (data->file_name, &st) != 0)
  524. {
  525. stat_error (data->file_name);
  526. skip_this_one = 1;
  527. }
  528. else if (! (st.st_dev == data->dev && st.st_ino == data->ino))
  529. {
  530. ERROR ((0, 0,
  531. _("%s: Directory renamed before its status could be extracted"),
  532. quotearg_colon (data->file_name)));
  533. skip_this_one = 1;
  534. }
  535. }
  536. if (! skip_this_one)
  537. {
  538. struct tar_stat_info sb;
  539. sb.stat.st_mode = data->mode;
  540. sb.stat.st_uid = data->uid;
  541. sb.stat.st_gid = data->gid;
  542. sb.atime = data->atime;
  543. sb.mtime = data->mtime;
  544. set_stat (data->file_name, &sb, cur_info,
  545. data->invert_permissions, data->permstatus, DIRTYPE);
  546. }
  547. delayed_set_stat_head = data->next;
  548. free (data);
  549. }
  550. }
  551. /* Extractor functions for various member types */
  552. static int
  553. extract_dir (char *file_name, int typeflag)
  554. {
  555. int status;
  556. mode_t mode;
  557. int interdir_made = 0;
  558. /* Save 'root device' to avoid purging mount points. */
  559. if (one_file_system_option && root_device == 0)
  560. {
  561. struct stat st;
  562. char *dir = xgetcwd ();
  563. if (deref_stat (true, dir, &st))
  564. stat_diag (dir);
  565. else
  566. root_device = st.st_dev;
  567. free (dir);
  568. }
  569. if (incremental_option)
  570. /* Read the entry and delete files that aren't listed in the archive. */
  571. purge_directory (file_name);
  572. else if (typeflag == GNUTYPE_DUMPDIR)
  573. skip_member ();
  574. mode = current_stat_info.stat.st_mode | (we_are_root ? 0 : MODE_WXUSR);
  575. if (0 < same_owner_option || current_stat_info.stat.st_mode & ~ MODE_RWX)
  576. mode &= S_IRWXU;
  577. while ((status = mkdir (file_name, mode)))
  578. {
  579. if (errno == EEXIST
  580. && (interdir_made
  581. || old_files_option == DEFAULT_OLD_FILES
  582. || old_files_option == OVERWRITE_OLD_FILES))
  583. {
  584. struct stat st;
  585. if (stat (file_name, &st) == 0)
  586. {
  587. if (interdir_made)
  588. {
  589. repair_delayed_set_stat (file_name, &st);
  590. return 0;
  591. }
  592. if (S_ISDIR (st.st_mode))
  593. {
  594. status = 0;
  595. mode = st.st_mode;
  596. break;
  597. }
  598. }
  599. errno = EEXIST;
  600. }
  601. switch (maybe_recoverable (file_name, &interdir_made))
  602. {
  603. case RECOVER_OK:
  604. continue;
  605. case RECOVER_SKIP:
  606. break;
  607. case RECOVER_NO:
  608. if (errno != EEXIST)
  609. {
  610. mkdir_error (file_name);
  611. return 1;
  612. }
  613. break;
  614. }
  615. break;
  616. }
  617. if (status == 0
  618. || old_files_option == DEFAULT_OLD_FILES
  619. || old_files_option == OVERWRITE_OLD_FILES)
  620. {
  621. if (status == 0)
  622. delay_set_stat (file_name, &current_stat_info,
  623. ((mode ^ current_stat_info.stat.st_mode)
  624. & MODE_RWX & ~ current_umask),
  625. ARCHIVED_PERMSTATUS);
  626. else /* For an already existing directory, invert_perms must be 0 */
  627. delay_set_stat (file_name, &current_stat_info,
  628. 0,
  629. UNKNOWN_PERMSTATUS);
  630. }
  631. return status;
  632. }
  633. static int
  634. open_output_file (char *file_name, int typeflag, mode_t mode)
  635. {
  636. int fd;
  637. int openflag = (O_WRONLY | O_BINARY | O_CREAT
  638. | (old_files_option == OVERWRITE_OLD_FILES
  639. ? O_TRUNC
  640. : O_EXCL));
  641. #if O_CTG
  642. /* Contiguous files (on the Masscomp) have to specify the size in
  643. the open call that creates them. */
  644. if (typeflag == CONTTYPE)
  645. fd = open (file_name, openflag | O_CTG, mode, current_stat_info.stat.st_size);
  646. else
  647. fd = open (file_name, openflag, mode);
  648. #else /* not O_CTG */
  649. if (typeflag == CONTTYPE)
  650. {
  651. static int conttype_diagnosed;
  652. if (!conttype_diagnosed)
  653. {
  654. conttype_diagnosed = 1;
  655. WARNOPT (WARN_CONTIGUOUS_CAST,
  656. (0, 0, _("Extracting contiguous files as regular files")));
  657. }
  658. }
  659. fd = open (file_name, openflag, mode);
  660. #endif /* not O_CTG */
  661. return fd;
  662. }
  663. static int
  664. extract_file (char *file_name, int typeflag)
  665. {
  666. int fd;
  667. off_t size;
  668. union block *data_block;
  669. int status;
  670. size_t count;
  671. size_t written;
  672. int interdir_made = 0;
  673. mode_t mode = current_stat_info.stat.st_mode & MODE_RWX & ~ current_umask;
  674. mode_t invert_permissions =
  675. 0 < same_owner_option ? mode & (S_IRWXG | S_IRWXO) : 0;
  676. /* FIXME: deal with protection issues. */
  677. if (to_stdout_option)
  678. fd = STDOUT_FILENO;
  679. else if (to_command_option)
  680. {
  681. fd = sys_exec_command (file_name, 'f', &current_stat_info);
  682. if (fd < 0)
  683. {
  684. skip_member ();
  685. return 0;
  686. }
  687. }
  688. else
  689. {
  690. int recover = RECOVER_NO;
  691. do
  692. fd = open_output_file (file_name, typeflag, mode ^ invert_permissions);
  693. while (fd < 0
  694. && (recover = maybe_recoverable (file_name, &interdir_made))
  695. == RECOVER_OK);
  696. if (fd < 0)
  697. {
  698. skip_member ();
  699. if (recover == RECOVER_SKIP)
  700. return 0;
  701. open_error (file_name);
  702. return 1;
  703. }
  704. }
  705. mv_begin (&current_stat_info);
  706. if (current_stat_info.is_sparse)
  707. sparse_extract_file (fd, &current_stat_info, &size);
  708. else
  709. for (size = current_stat_info.stat.st_size; size > 0; )
  710. {
  711. mv_size_left (size);
  712. /* Locate data, determine max length writeable, write it,
  713. block that we have used the data, then check if the write
  714. worked. */
  715. data_block = find_next_block ();
  716. if (! data_block)
  717. {
  718. ERROR ((0, 0, _("Unexpected EOF in archive")));
  719. break; /* FIXME: What happens, then? */
  720. }
  721. written = available_space_after (data_block);
  722. if (written > size)
  723. written = size;
  724. errno = 0;
  725. count = full_write (fd, data_block->buffer, written);
  726. size -= written;
  727. set_next_block_after ((union block *)
  728. (data_block->buffer + written - 1));
  729. if (count != written)
  730. {
  731. if (!to_command_option)
  732. write_error_details (file_name, count, written);
  733. /* FIXME: shouldn't we restore from backup? */
  734. break;
  735. }
  736. }
  737. skip_file (size);
  738. mv_end ();
  739. /* If writing to stdout, don't try to do anything to the filename;
  740. it doesn't exist, or we don't want to touch it anyway. */
  741. if (to_stdout_option)
  742. return 0;
  743. status = close (fd);
  744. if (status < 0)
  745. close_error (file_name);
  746. if (to_command_option)
  747. sys_wait_command ();
  748. else
  749. set_stat (file_name, &current_stat_info, NULL, invert_permissions,
  750. (old_files_option == OVERWRITE_OLD_FILES ?
  751. UNKNOWN_PERMSTATUS : ARCHIVED_PERMSTATUS),
  752. typeflag);
  753. return status;
  754. }
  755. /* Create a placeholder file with name FILE_NAME, which will be
  756. replaced after other extraction is done by a symbolic link if
  757. IS_SYMLINK is true, and by a hard link otherwise. Set
  758. *INTERDIR_MADE if an intermediate directory is made in the
  759. process. */
  760. static int
  761. create_placeholder_file (char *file_name, bool is_symlink, int *interdir_made)
  762. {
  763. int fd;
  764. struct stat st;
  765. while ((fd = open (file_name, O_WRONLY | O_CREAT | O_EXCL, 0)) < 0)
  766. {
  767. switch (maybe_recoverable (file_name, interdir_made))
  768. {
  769. case RECOVER_OK:
  770. continue;
  771. case RECOVER_SKIP:
  772. return 0;
  773. case RECOVER_NO:
  774. open_error (file_name);
  775. return -1;
  776. }
  777. }
  778. if (fstat (fd, &st) != 0)
  779. {
  780. stat_error (file_name);
  781. close (fd);
  782. }
  783. else if (close (fd) != 0)
  784. close_error (file_name);
  785. else
  786. {
  787. struct delayed_set_stat *h;
  788. struct delayed_link *p =
  789. xmalloc (offsetof (struct delayed_link, target)
  790. + strlen (current_stat_info.link_name)
  791. + 1);
  792. p->next = delayed_link_head;
  793. delayed_link_head = p;
  794. p->dev = st.st_dev;
  795. p->ino = st.st_ino;
  796. p->mtime = get_stat_mtime (&st);
  797. p->is_symlink = is_symlink;
  798. if (is_symlink)
  799. {
  800. p->uid = current_stat_info.stat.st_uid;
  801. p->gid = current_stat_info.stat.st_gid;
  802. }
  803. p->sources = xmalloc (offsetof (struct string_list, string)
  804. + strlen (file_name) + 1);
  805. p->sources->next = 0;
  806. strcpy (p->sources->string, file_name);
  807. strcpy (p->target, current_stat_info.link_name);
  808. h = delayed_set_stat_head;
  809. if (h && ! h->after_links
  810. && strncmp (file_name, h->file_name, h->file_name_len) == 0
  811. && ISSLASH (file_name[h->file_name_len])
  812. && (last_component (file_name) == file_name + h->file_name_len + 1))
  813. {
  814. do
  815. {
  816. h->after_links = 1;
  817. if (stat (h->file_name, &st) != 0)
  818. stat_error (h->file_name);
  819. else
  820. {
  821. h->dev = st.st_dev;
  822. h->ino = st.st_ino;
  823. }
  824. }
  825. while ((h = h->next) && ! h->after_links);
  826. }
  827. return 0;
  828. }
  829. return -1;
  830. }
  831. static int
  832. extract_link (char *file_name, int typeflag)
  833. {
  834. int interdir_made = 0;
  835. char const *link_name;
  836. int rc;
  837. link_name = current_stat_info.link_name;
  838. if (! absolute_names_option && contains_dot_dot (link_name))
  839. return create_placeholder_file (file_name, false, &interdir_made);
  840. do
  841. {
  842. struct stat st1, st2;
  843. int e;
  844. int status = link (link_name, file_name);
  845. e = errno;
  846. if (status == 0)
  847. {
  848. struct delayed_link *ds = delayed_link_head;
  849. if (ds && lstat (link_name, &st1) == 0)
  850. for (; ds; ds = ds->next)
  851. if (ds->dev == st1.st_dev
  852. && ds->ino == st1.st_ino
  853. && timespec_cmp (ds->mtime, get_stat_mtime (&st1)) == 0)
  854. {
  855. struct string_list *p = xmalloc (offsetof (struct string_list, string)
  856. + strlen (file_name) + 1);
  857. strcpy (p->string, file_name);
  858. p->next = ds->sources;
  859. ds->sources = p;
  860. break;
  861. }
  862. return 0;
  863. }
  864. else if ((e == EEXIST && strcmp (link_name, file_name) == 0)
  865. || (lstat (link_name, &st1) == 0
  866. && lstat (file_name, &st2) == 0
  867. && st1.st_dev == st2.st_dev
  868. && st1.st_ino == st2.st_ino))
  869. return 0;
  870. errno = e;
  871. }
  872. while ((rc = maybe_recoverable (file_name, &interdir_made)) == RECOVER_OK);
  873. if (rc == RECOVER_SKIP)
  874. return 0;
  875. if (!(incremental_option && errno == EEXIST))
  876. {
  877. link_error (link_name, file_name);
  878. return 1;
  879. }
  880. return 0;
  881. }
  882. static int
  883. extract_symlink (char *file_name, int typeflag)
  884. {
  885. #ifdef HAVE_SYMLINK
  886. int interdir_made = 0;
  887. if (! absolute_names_option
  888. && (IS_ABSOLUTE_FILE_NAME (current_stat_info.link_name)
  889. || contains_dot_dot (current_stat_info.link_name)))
  890. return create_placeholder_file (file_name, true, &interdir_made);
  891. while (symlink (current_stat_info.link_name, file_name))
  892. switch (maybe_recoverable (file_name, &interdir_made))
  893. {
  894. case RECOVER_OK:
  895. continue;
  896. case RECOVER_SKIP:
  897. return 0;
  898. case RECOVER_NO:
  899. symlink_error (current_stat_info.link_name, file_name);
  900. return -1;
  901. }
  902. set_stat (file_name, &current_stat_info, NULL, 0, 0, SYMTYPE);
  903. return 0;
  904. #else
  905. static int warned_once;
  906. if (!warned_once)
  907. {
  908. warned_once = 1;
  909. WARNOPT (WARN_SYMBOLIC_CAST,
  910. (0, 0,
  911. _("Attempting extraction of symbolic links as hard links")));
  912. }
  913. return extract_link (file_name, typeflag);
  914. #endif
  915. }
  916. #if S_IFCHR || S_IFBLK
  917. static int
  918. extract_node (char *file_name, int typeflag)
  919. {
  920. int status;
  921. int interdir_made = 0;
  922. mode_t mode = current_stat_info.stat.st_mode & ~ current_umask;
  923. mode_t invert_permissions =
  924. 0 < same_owner_option ? mode & (S_IRWXG | S_IRWXO) : 0;
  925. while (mknod (file_name, mode ^ invert_permissions,
  926. current_stat_info.stat.st_rdev))
  927. switch (maybe_recoverable (file_name, &interdir_made))
  928. {
  929. case RECOVER_OK:
  930. continue;
  931. case RECOVER_SKIP:
  932. return 0;
  933. case RECOVER_NO:
  934. mknod_error (file_name);
  935. return -1;
  936. }
  937. set_stat (file_name, &current_stat_info, NULL, invert_permissions,
  938. ARCHIVED_PERMSTATUS, typeflag);
  939. return status;
  940. }
  941. #endif
  942. #if HAVE_MKFIFO || defined mkfifo
  943. static int
  944. extract_fifo (char *file_name, int typeflag)
  945. {
  946. int status;
  947. int interdir_made = 0;
  948. mode_t mode = current_stat_info.stat.st_mode & ~ current_umask;
  949. mode_t invert_permissions =
  950. 0 < same_owner_option ? mode & (S_IRWXG | S_IRWXO) : 0;
  951. while ((status = mkfifo (file_name, mode)) != 0)
  952. switch (maybe_recoverable (file_name, &interdir_made))
  953. {
  954. case RECOVER_OK:
  955. continue;
  956. case RECOVER_SKIP:
  957. return 0;
  958. case RECOVER_NO:
  959. mkfifo_error (file_name);
  960. return -1;
  961. }
  962. set_stat (file_name, &current_stat_info, NULL, invert_permissions,
  963. ARCHIVED_PERMSTATUS, typeflag);
  964. return 0;
  965. }
  966. #endif
  967. static int
  968. extract_volhdr (char *file_name, int typeflag)
  969. {
  970. skip_member ();
  971. return 0;
  972. }
  973. static int
  974. extract_failure (char *file_name, int typeflag)
  975. {
  976. return 1;
  977. }
  978. typedef int (*tar_extractor_t) (char *file_name, int typeflag);
  979. /* Prepare to extract a file. Find extractor function.
  980. Return zero if extraction should not proceed. */
  981. static int
  982. prepare_to_extract (char const *file_name, int typeflag, tar_extractor_t *fun)
  983. {
  984. int rc = 1;
  985. if (EXTRACT_OVER_PIPE)
  986. rc = 0;
  987. /* Select the extractor */
  988. switch (typeflag)
  989. {
  990. case GNUTYPE_SPARSE:
  991. *fun = extract_file;
  992. rc = 1;
  993. break;
  994. case AREGTYPE:
  995. case REGTYPE:
  996. case CONTTYPE:
  997. /* Appears to be a file. But BSD tar uses the convention that a slash
  998. suffix means a directory. */
  999. if (current_stat_info.had_trailing_slash)
  1000. *fun = extract_dir;
  1001. else
  1002. {
  1003. *fun = extract_file;
  1004. rc = 1;
  1005. }
  1006. break;
  1007. case SYMTYPE:
  1008. *fun = extract_symlink;
  1009. break;
  1010. case LNKTYPE:
  1011. *fun = extract_link;
  1012. break;
  1013. #if S_IFCHR
  1014. case CHRTYPE:
  1015. current_stat_info.stat.st_mode |= S_IFCHR;
  1016. *fun = extract_node;
  1017. break;
  1018. #endif
  1019. #if S_IFBLK
  1020. case BLKTYPE:
  1021. current_stat_info.stat.st_mode |= S_IFBLK;
  1022. *fun = extract_node;
  1023. break;
  1024. #endif
  1025. #if HAVE_MKFIFO || defined mkfifo
  1026. case FIFOTYPE:
  1027. *fun = extract_fifo;
  1028. break;
  1029. #endif
  1030. case DIRTYPE:
  1031. case GNUTYPE_DUMPDIR:
  1032. *fun = extract_dir;
  1033. if (current_stat_info.is_dumpdir)
  1034. delay_directory_restore_option = true;
  1035. break;
  1036. case GNUTYPE_VOLHDR:
  1037. *fun = extract_volhdr;
  1038. break;
  1039. case GNUTYPE_MULTIVOL:
  1040. ERROR ((0, 0,
  1041. _("%s: Cannot extract -- file is continued from another volume"),
  1042. quotearg_colon (current_stat_info.file_name)));
  1043. *fun = extract_failure;
  1044. break;
  1045. case GNUTYPE_LONGNAME:
  1046. case GNUTYPE_LONGLINK:
  1047. ERROR ((0, 0, _("Unexpected long name header")));
  1048. *fun = extract_failure;
  1049. break;
  1050. default:
  1051. WARNOPT (WARN_UNKNOWN_CAST,
  1052. (0, 0,
  1053. _("%s: Unknown file type `%c', extracted as normal file"),
  1054. quotearg_colon (file_name), typeflag));
  1055. *fun = extract_file;
  1056. }
  1057. /* Determine whether the extraction should proceed */
  1058. if (rc == 0)
  1059. return 0;
  1060. switch (old_files_option)
  1061. {
  1062. case UNLINK_FIRST_OLD_FILES:
  1063. if (!remove_any_file (file_name,
  1064. recursive_unlink_option ? RECURSIVE_REMOVE_OPTION
  1065. : ORDINARY_REMOVE_OPTION)
  1066. && errno && errno != ENOENT)
  1067. {
  1068. unlink_error (file_name);
  1069. return 0;
  1070. }
  1071. break;
  1072. case KEEP_NEWER_FILES:
  1073. if (file_newer_p (file_name, &current_stat_info))
  1074. {
  1075. WARNOPT (WARN_IGNORE_NEWER,
  1076. (0, 0, _("Current %s is newer or same age"),
  1077. quote (file_name)));
  1078. return 0;
  1079. }
  1080. break;
  1081. default:
  1082. break;
  1083. }
  1084. return 1;
  1085. }
  1086. /* Extract a file from the archive. */
  1087. void
  1088. extract_archive (void)
  1089. {
  1090. char typeflag;
  1091. tar_extractor_t fun;
  1092. fatal_exit_hook = extract_finish;
  1093. /* Try to disable the ability to unlink a directory. */
  1094. priv_set_remove_linkdir ();
  1095. set_next_block_after (current_header);
  1096. decode_header (current_header, &current_stat_info, &current_format, 1);
  1097. if (!current_stat_info.file_name[0]
  1098. || (interactive_option
  1099. && !confirm ("extract", current_stat_info.file_name)))
  1100. {
  1101. skip_member ();
  1102. return;
  1103. }
  1104. /* Print the block from current_header and current_stat. */
  1105. if (verbose_option)
  1106. print_header (&current_stat_info, current_header, -1);
  1107. /* Restore stats for all non-ancestor directories, unless
  1108. it is an incremental archive.
  1109. (see NOTICE in the comment to delay_set_stat above) */
  1110. if (!delay_directory_restore_option)
  1111. apply_nonancestor_delayed_set_stat (current_stat_info.file_name, 0);
  1112. /* Take a safety backup of a previously existing file. */
  1113. if (backup_option)
  1114. if (!maybe_backup_file (current_stat_info.file_name, 0))
  1115. {
  1116. int e = errno;
  1117. ERROR ((0, e, _("%s: Was unable to backup this file"),
  1118. quotearg_colon (current_stat_info.file_name)));
  1119. skip_member ();
  1120. return;
  1121. }
  1122. /* Extract the archive entry according to its type. */
  1123. /* KLUDGE */
  1124. typeflag = sparse_member_p (&current_stat_info) ?
  1125. GNUTYPE_SPARSE : current_header->header.typeflag;
  1126. if (prepare_to_extract (current_stat_info.file_name, typeflag, &fun))
  1127. {
  1128. if (fun && (*fun) (current_stat_info.file_name, typeflag)
  1129. && backup_option)
  1130. undo_last_backup ();
  1131. }
  1132. else
  1133. skip_member ();
  1134. }
  1135. /* Extract the symbolic links whose final extraction were delayed. */
  1136. static void
  1137. apply_delayed_links (void)
  1138. {
  1139. struct delayed_link *ds;
  1140. for (ds = delayed_link_head; ds; )
  1141. {
  1142. struct string_list *sources = ds->sources;
  1143. char const *valid_source = 0;
  1144. for (sources = ds->sources; sources; sources = sources->next)
  1145. {
  1146. char const *source = sources->string;
  1147. struct stat st;
  1148. /* Make sure the placeholder file is still there. If not,
  1149. don't create a link, as the placeholder was probably
  1150. removed by a later extraction. */
  1151. if (lstat (source, &st) == 0
  1152. && st.st_dev == ds->dev
  1153. && st.st_ino == ds->ino
  1154. && timespec_cmp (get_stat_mtime (&st), ds->mtime) == 0)
  1155. {
  1156. /* Unlink the placeholder, then create a hard link if possible,
  1157. a symbolic link otherwise. */
  1158. if (unlink (source) != 0)
  1159. unlink_error (source);
  1160. else if (valid_source && link (valid_source, source) == 0)
  1161. ;
  1162. else if (!ds->is_symlink)
  1163. {
  1164. if (link (ds->target, source) != 0)
  1165. link_error (ds->target, source);
  1166. }
  1167. else if (symlink (ds->target, source) != 0)
  1168. symlink_error (ds->target, source);
  1169. else
  1170. {
  1171. struct tar_stat_info st1;
  1172. st1.stat.st_uid = ds->uid;
  1173. st1.stat.st_gid = ds->gid;
  1174. set_stat (source, &st1, NULL, 0, 0, SYMTYPE);
  1175. valid_source = source;
  1176. }
  1177. }
  1178. }
  1179. for (sources = ds->sources; sources; )
  1180. {
  1181. struct string_list *next = sources->next;
  1182. free (sources);
  1183. sources = next;
  1184. }
  1185. {
  1186. struct delayed_link *next = ds->next;
  1187. free (ds);
  1188. ds = next;
  1189. }
  1190. }
  1191. delayed_link_head = 0;
  1192. }
  1193. /* Finish the extraction of an archive. */
  1194. void
  1195. extract_finish (void)
  1196. {
  1197. /* First, fix the status of ordinary directories that need fixing. */
  1198. apply_nonancestor_delayed_set_stat ("", 0);
  1199. /* Then, apply delayed links, so that they don't affect delayed
  1200. directory status-setting for ordinary directories. */
  1201. apply_delayed_links ();
  1202. /* Finally, fix the status of directories that are ancestors
  1203. of delayed links. */
  1204. apply_nonancestor_delayed_set_stat ("", 1);
  1205. }
  1206. bool
  1207. rename_directory (char *src, char *dst)
  1208. {
  1209. if (rename (src, dst))
  1210. {
  1211. int e = errno;
  1212. switch (e)
  1213. {
  1214. case ENOENT:
  1215. if (make_directories (dst))
  1216. {
  1217. if (rename (src, dst) == 0)
  1218. return true;
  1219. e = errno;
  1220. }
  1221. break;
  1222. case EXDEV:
  1223. /* FIXME: Fall back to recursive copying */
  1224. default:
  1225. break;
  1226. }
  1227. ERROR ((0, e, _("Cannot rename %s to %s"),
  1228. quote_n (0, src),
  1229. quote_n (1, dst)));
  1230. return false;
  1231. }
  1232. return true;
  1233. }