archive_read_disk_posix.c (344673) | archive_read_disk_posix.c (348607) |
---|---|
1/*- 2 * Copyright (c) 2003-2009 Tim Kientzle 3 * Copyright (c) 2010-2012 Michihiro NAKAJIMA 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: --- 895 unchanged lines hidden (view full) --- 904 archive_set_error(&a->archive, errno, 905 "%s: Cannot stat", 906 tree_current_path(t)); 907 tree_enter_initial_dir(t); 908 return (ARCHIVE_FAILED); 909 } 910 } 911 break; | 1/*- 2 * Copyright (c) 2003-2009 Tim Kientzle 3 * Copyright (c) 2010-2012 Michihiro NAKAJIMA 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: --- 895 unchanged lines hidden (view full) --- 904 archive_set_error(&a->archive, errno, 905 "%s: Cannot stat", 906 tree_current_path(t)); 907 tree_enter_initial_dir(t); 908 return (ARCHIVE_FAILED); 909 } 910 } 911 break; |
912 } | 912 } |
913 } while (lst == NULL); 914 915#ifdef __APPLE__ 916 if (a->flags & ARCHIVE_READDISK_MAC_COPYFILE) { 917 /* If we're using copyfile(), ignore "._XXX" files. */ 918 const char *bname = strrchr(tree_current_path(t), '/'); 919 if (bname == NULL) 920 bname = tree_current_path(t); --- 369 unchanged lines hidden (view full) --- 1290 1291 archive_check_magic(_a, ARCHIVE_READ_DISK_MAGIC, 1292 ARCHIVE_STATE_HEADER | ARCHIVE_STATE_DATA, 1293 "archive_read_disk_descend"); 1294 1295 if (t->visit_type != TREE_REGULAR || !t->descend) 1296 return (ARCHIVE_OK); 1297 | 913 } while (lst == NULL); 914 915#ifdef __APPLE__ 916 if (a->flags & ARCHIVE_READDISK_MAC_COPYFILE) { 917 /* If we're using copyfile(), ignore "._XXX" files. */ 918 const char *bname = strrchr(tree_current_path(t), '/'); 919 if (bname == NULL) 920 bname = tree_current_path(t); --- 369 unchanged lines hidden (view full) --- 1290 1291 archive_check_magic(_a, ARCHIVE_READ_DISK_MAGIC, 1292 ARCHIVE_STATE_HEADER | ARCHIVE_STATE_DATA, 1293 "archive_read_disk_descend"); 1294 1295 if (t->visit_type != TREE_REGULAR || !t->descend) 1296 return (ARCHIVE_OK); 1297 |
1298 /* 1299 * We must not treat the initial specified path as a physical dir, 1300 * because if we do then we will try and ascend out of it by opening 1301 * ".." which is (a) wrong and (b) causes spurious permissions errors 1302 * if ".." is not readable by us. Instead, treat it as if it were a 1303 * symlink. (This uses an extra fd, but it can only happen once at the 1304 * top level of a traverse.) But we can't necessarily assume t->st is 1305 * valid here (though t->lst is), which complicates the logic a 1306 * little. 1307 */ |
|
1298 if (tree_current_is_physical_dir(t)) { 1299 tree_push(t, t->basename, t->current_filesystem_id, 1300 t->lst.st_dev, t->lst.st_ino, &t->restore_time); | 1308 if (tree_current_is_physical_dir(t)) { 1309 tree_push(t, t->basename, t->current_filesystem_id, 1310 t->lst.st_dev, t->lst.st_ino, &t->restore_time); |
1301 t->stack->flags |= isDir; | 1311 if (t->stack->parent->parent != NULL) 1312 t->stack->flags |= isDir; 1313 else 1314 t->stack->flags |= isDirLink; |
1302 } else if (tree_current_is_dir(t)) { 1303 tree_push(t, t->basename, t->current_filesystem_id, 1304 t->st.st_dev, t->st.st_ino, &t->restore_time); 1305 t->stack->flags |= isDirLink; 1306 } 1307 t->descend = 0; 1308 return (ARCHIVE_OK); 1309} --- 836 unchanged lines hidden (view full) --- 2146 archive_string_ensure(&t->path, 31); 2147 t->initial_symlink_mode = symlink_mode; 2148 return (tree_reopen(t, path, restore_time)); 2149} 2150 2151static struct tree * 2152tree_reopen(struct tree *t, const char *path, int restore_time) 2153{ | 1315 } else if (tree_current_is_dir(t)) { 1316 tree_push(t, t->basename, t->current_filesystem_id, 1317 t->st.st_dev, t->st.st_ino, &t->restore_time); 1318 t->stack->flags |= isDirLink; 1319 } 1320 t->descend = 0; 1321 return (ARCHIVE_OK); 1322} --- 836 unchanged lines hidden (view full) --- 2159 archive_string_ensure(&t->path, 31); 2160 t->initial_symlink_mode = symlink_mode; 2161 return (tree_reopen(t, path, restore_time)); 2162} 2163 2164static struct tree * 2165tree_reopen(struct tree *t, const char *path, int restore_time) 2166{ |
2167#if defined(O_PATH) 2168 /* Linux */ 2169 const int o_flag = O_PATH; 2170#elif defined(O_SEARCH) 2171 /* SunOS */ 2172 const int o_flag = O_SEARCH; 2173#elif defined(O_EXEC) 2174 /* FreeBSD */ 2175 const int o_flag = O_EXEC; 2176#endif 2177 |
|
2154 t->flags = (restore_time != 0)?needsRestoreTimes:0; 2155 t->flags |= onInitialDir; 2156 t->visit_type = 0; 2157 t->tree_errno = 0; 2158 t->dirname_length = 0; 2159 t->depth = 0; 2160 t->descend = 0; 2161 t->current = NULL; --- 5 unchanged lines hidden (view full) --- 2167 t->entry_remaining_bytes = 0; 2168 t->initial_filesystem_id = -1; 2169 2170 /* First item is set up a lot like a symlink traversal. */ 2171 tree_push(t, path, 0, 0, 0, NULL); 2172 t->stack->flags = needsFirstVisit; 2173 t->maxOpenCount = t->openCount = 1; 2174 t->initial_dir_fd = open(".", O_RDONLY | O_CLOEXEC); | 2178 t->flags = (restore_time != 0)?needsRestoreTimes:0; 2179 t->flags |= onInitialDir; 2180 t->visit_type = 0; 2181 t->tree_errno = 0; 2182 t->dirname_length = 0; 2183 t->depth = 0; 2184 t->descend = 0; 2185 t->current = NULL; --- 5 unchanged lines hidden (view full) --- 2191 t->entry_remaining_bytes = 0; 2192 t->initial_filesystem_id = -1; 2193 2194 /* First item is set up a lot like a symlink traversal. */ 2195 tree_push(t, path, 0, 0, 0, NULL); 2196 t->stack->flags = needsFirstVisit; 2197 t->maxOpenCount = t->openCount = 1; 2198 t->initial_dir_fd = open(".", O_RDONLY | O_CLOEXEC); |
2199#if defined(O_PATH) || defined(O_SEARCH) || defined(O_EXEC) 2200 /* 2201 * Most likely reason to fail opening "." is that it's not readable, 2202 * so try again for execute. The consequences of not opening this are 2203 * unhelpful and unnecessary errors later. 2204 */ 2205 if (t->initial_dir_fd < 0) 2206 t->initial_dir_fd = open(".", o_flag | O_CLOEXEC); 2207#endif |
|
2175 __archive_ensure_cloexec_flag(t->initial_dir_fd); 2176 t->working_dir_fd = tree_dup(t->initial_dir_fd); 2177 return (t); 2178} 2179 2180static int 2181tree_descent(struct tree *t) 2182{ --- 291 unchanged lines hidden (view full) --- 2474{ 2475 if (!(t->flags & hasStat)) { 2476#ifdef HAVE_FSTATAT 2477 if (fstatat(tree_current_dir_fd(t), 2478 tree_current_access_path(t), &t->st, 0) != 0) 2479#else 2480 if (tree_enter_working_dir(t) != 0) 2481 return NULL; | 2208 __archive_ensure_cloexec_flag(t->initial_dir_fd); 2209 t->working_dir_fd = tree_dup(t->initial_dir_fd); 2210 return (t); 2211} 2212 2213static int 2214tree_descent(struct tree *t) 2215{ --- 291 unchanged lines hidden (view full) --- 2507{ 2508 if (!(t->flags & hasStat)) { 2509#ifdef HAVE_FSTATAT 2510 if (fstatat(tree_current_dir_fd(t), 2511 tree_current_access_path(t), &t->st, 0) != 0) 2512#else 2513 if (tree_enter_working_dir(t) != 0) 2514 return NULL; |
2482 if (stat(tree_current_access_path(t), &t->st) != 0) | 2515 if (la_stat(tree_current_access_path(t), &t->st) != 0) |
2483#endif 2484 return NULL; 2485 t->flags |= hasStat; 2486 } 2487 return (&t->st); 2488} 2489 2490/* --- 200 unchanged lines hidden --- | 2516#endif 2517 return NULL; 2518 t->flags |= hasStat; 2519 } 2520 return (&t->st); 2521} 2522 2523/* --- 200 unchanged lines hidden --- |