Changeset 745 for trunk/server/source3/utils/smbget.c
- Timestamp:
- Nov 27, 2012, 4:43:17 PM (13 years ago)
- Location:
- trunk/server
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/server
- Property svn:mergeinfo changed
/vendor/current merged: 581,587,591,594,597,600,615,618,740
- Property svn:mergeinfo changed
-
trunk/server/source3/utils/smbget.c
r599 r745 8 8 the Free Software Foundation; either version 3 of the License, or 9 9 (at your option) any later version. 10 10 11 11 This program is distributed in the hope that it will be useful, 12 12 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 14 GNU General Public License for more details. 15 15 16 16 You should have received a copy of the GNU General Public License 17 17 along with this program. If not, see <http://www.gnu.org/licenses/>. */ 18 18 19 19 #include "includes.h" 20 #include "system/filesys.h" 21 #include "popt_common.h" 20 22 #include "libsmbclient.h" 21 23 … … 50 52 static int blocksize = SMB_DEFAULT_BLOCKSIZE; 51 53 52 static int smb_download_file(const char *base, const char *name, int recursive, int resume, char *outfile); 54 static int smb_download_file(const char *base, const char *name, int recursive, 55 int resume, int toplevel, char *outfile); 53 56 54 57 static int get_num_cols(void) … … 75 78 static void human_readable(off_t s, char *buffer, int l) 76 79 { 77 if(s > 1024 * 1024 * 1024) snprintf(buffer, l, "%.2fGB", 78 1.0 * s / (1024 * 1024 * 1024)); 79 else if(s > 1024 * 1024) snprintf(buffer, l, "%.2fMB", 80 1.0 * s / (1024 * 1024)); 81 else if(s > 1024) snprintf(buffer, l, "%.2fkB", 1.0 * s / 1024); 82 else snprintf(buffer, l, OFF_T_FORMAT"b", (OFF_T_FORMAT_CAST)s); 80 if (s > 1024 * 1024 * 1024) { 81 snprintf(buffer, l, "%.2fGB", 1.0 * s / (1024 * 1024 * 1024)); 82 } else if (s > 1024 * 1024) { 83 snprintf(buffer, l, "%.2fMB", 1.0 * s / (1024 * 1024)); 84 } else if (s > 1024) { 85 snprintf(buffer, l, "%.2fkB", 1.0 * s / 1024); 86 } else { 87 snprintf(buffer, l, OFF_T_FORMAT"b", (OFF_T_FORMAT_CAST)s); 88 } 83 89 } 84 90 … … 138 144 dirhandle = smbc_opendir(path); 139 145 if(dirhandle < 1) { 140 if(errno == ENOTDIR) return smb_download_file(base, name, 1, resume, NULL); 146 if (errno == ENOTDIR) { 147 return smb_download_file(base, name, 1, resume, 148 0, NULL); 149 } 141 150 fprintf(stderr, "Can't open directory %s: %s\n", path, strerror(errno)); 142 151 return 1; … … 145 154 while(*relname == '/')relname++; 146 155 mkdir(relname, 0755); 147 156 148 157 tmpname = SMB_STRDUP(name); 149 158 … … 168 177 169 178 case SMBC_FILE: 170 ret = smb_download_file(base, newname, 1, resume, NULL); 179 ret = smb_download_file(base, newname, 1, resume, 0, 180 NULL); 171 181 break; 172 182 … … 182 192 if(!quiet)printf("Ignoring comms share %s\n", dirent->name); 183 193 break; 184 194 185 195 case SMBC_IPC_SHARE: 186 196 if(!quiet)printf("Ignoring ipc$ share %s\n", dirent->name); … … 201 211 return 1; 202 212 } 203 213 204 214 if(chmod(relname, remotestat.st_mode) < 0) { 205 215 fprintf(stderr, "Unable to change mode of local dir %s to %o\n", relname, … … 250 260 return; 251 261 } 252 262 253 263 if(columns) { 254 264 int required = strlen(name), available = columns - len - strlen("[] "); … … 269 279 /* Return 1 on error, 0 on success. */ 270 280 271 static int smb_download_file(const char *base, const char *name, int recursive, int resume, char *outfile) { 281 static int smb_download_file(const char *base, const char *name, int recursive, 282 int resume, int toplevel, char *outfile) 283 { 272 284 int remotehandle, localhandle; 273 time_t start_time = time (NULL);285 time_t start_time = time_mono(NULL); 274 286 const char *newpath; 275 287 char path[SMB_MAXPATHLEN]; … … 280 292 281 293 snprintf(path, SMB_MAXPATHLEN-1, "%s%s%s", base, (*base && *name && name[0] != '/' && base[strlen(base)-1] != '/')?"/":"", name); 282 294 283 295 remotehandle = smbc_open(path, O_RDONLY, 0755); 284 296 … … 325 337 } else newpath = name; 326 338 327 if(newpath[0] == '/')newpath++; 328 339 if (!toplevel && (newpath[0] == '/')) { 340 newpath++; 341 } 342 329 343 /* Open local file according to the mode */ 330 344 if(update) { … … 353 367 return 1; 354 368 } 355 369 356 370 if (fstat(localhandle, &localstat) != 0) { 357 371 fprintf(stderr, "Can't fstat %s: %s\n", newpath, strerror(errno)); … … 404 418 (OFF_T_FORMAT_CAST)off1, 405 419 (OFF_T_FORMAT_CAST)off2); 420 smbc_close(remotehandle); close(localhandle); 406 421 return 1; 407 422 } … … 435 450 436 451 readbuf = (char *)SMB_MALLOC(blocksize); 452 if (!readbuf) { 453 return 1; 454 } 437 455 438 456 /* Now, download all bytes from offset_download to the end */ … … 459 477 if(dots)fputc('.', stderr); 460 478 else if(!quiet) { 461 print_progress(newpath, start_time, time(NULL), start_offset, curpos, remotestat.st_size); 479 print_progress(newpath, start_time, time_mono(NULL), 480 start_offset, curpos, remotestat.st_size); 462 481 } 463 482 } … … 499 518 human_readable(total_bytes, bs, sizeof(bs)); 500 519 if(!quiet)fprintf(stderr, "Downloaded %s in %lu seconds\n", bs, 501 (unsigned long)(time (NULL) - total_start_time));520 (unsigned long)(time_mono(NULL) - total_start_time)); 502 521 exit(0); 503 522 } … … 655 674 "require"); 656 675 } 657 676 658 677 columns = get_num_cols(); 659 678 660 total_start_time = time (NULL);679 total_start_time = time_mono(NULL); 661 680 662 681 while ( (file = poptGetArg(pc)) ) { 663 682 if (!recursive) 664 ret = smb_download_file(file, "", recursive, resume, outputfile); 683 ret = smb_download_file(file, "", recursive, resume, 684 1, outputfile); 665 685 else 666 686 ret = smb_download_dir(file, "", resume);
Note:
See TracChangeset
for help on using the changeset viewer.