Bugzilla – Attachment 2199 Details for
Bug 2021
sftp resume support (using size and offset)
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Resume diff with copyright
resume3.diff (text/plain), 5.44 KB, created by
Loganaden Velvindron
on 2012-12-12 06:07:52 AEDT
(
hide
)
Description:
Resume diff with copyright
Filename:
MIME Type:
Creator:
Loganaden Velvindron
Created:
2012-12-12 06:07:52 AEDT
Size:
5.44 KB
patch
obsolete
>Index: sftp-client.h >=================================================================== >RCS file: /cvs/openssh/sftp-client.h,v >retrieving revision 1.20 >diff -u -p -r1.20 sftp-client.h >--- sftp-client.h 4 Dec 2010 22:02:48 -0000 1.20 >+++ sftp-client.h 11 Dec 2012 19:00:49 -0000 >@@ -106,7 +106,7 @@ int do_symlink(struct sftp_conn *, char > * Download 'remote_path' to 'local_path'. Preserve permissions and times > * if 'pflag' is set > */ >-int do_download(struct sftp_conn *, char *, char *, Attrib *, int); >+int do_download(struct sftp_conn *, char *, char *, Attrib *, int, int); > > /* > * Recursively download 'remote_directory' to 'local_directory'. Preserve >Index: sftp-client.c >=================================================================== >RCS file: /cvs/openssh/sftp-client.c,v >retrieving revision 1.108 >diff -u -p -r1.108 sftp-client.c >--- sftp-client.c 2 Jul 2012 12:15:39 -0000 1.108 >+++ sftp-client.c 11 Dec 2012 19:00:53 -0000 >@@ -15,6 +15,24 @@ > * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. > */ > >+/* >+ * Copyright (c) 2012 Loganaden Velvindron >+ * >+ * Permission to use, copy, modify, and distribute this software for any >+ * purpose with or without fee is hereby granted, provided that the above >+ * copyright notice and this permission notice appear in all copies. >+ * >+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES >+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF >+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR >+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES >+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN >+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF >+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. >+ * >+ * Sponsored by AfriNIC. >+ */ >+ > /* XXX: memleaks */ > /* XXX: signed vs unsigned */ > /* XXX: remove all logging, only return status codes */ >@@ -988,16 +1006,17 @@ send_read_request(struct sftp_conn *conn > > int > do_download(struct sftp_conn *conn, char *remote_path, char *local_path, >- Attrib *a, int pflag) >+ Attrib *a, int pflag, int resume) > { > Attrib junk; > Buffer msg; > char *handle; >- int local_fd, status = 0, write_error; >+ int local_fd = -1, status = 0, write_error, bigger; > int read_error, write_errno; >- u_int64_t offset, size; >+ u_int64_t offset = 0, size, highwater; > u_int handle_len, mode, type, id, buflen, num_req, max_req; > off_t progress_counter; >+ struct stat st; > struct request { > u_int id; > u_int len; >@@ -1050,11 +1069,36 @@ do_download(struct sftp_conn *conn, char > return(-1); > } > >- local_fd = open(local_path, O_WRONLY | O_CREAT | O_TRUNC, >- mode | S_IWRITE); >+ if (resume) { >+ if (stat(local_path, &st) == -1) { >+ offset = 0; >+ highwater = 0; >+ local_fd = open(local_path, O_WRONLY | O_CREAT, >+ mode | S_IWRITE); >+ } >+ else { >+ if ((size_t)st.st_size > size) { >+ bigger = 1; >+ local_fd = -1; >+ } >+ else { >+ offset = st.st_size; >+ highwater = st.st_size; >+ local_fd = open(local_path, >+ O_WRONLY | O_CREAT, >+ mode | S_IWRITE); >+ } >+ } >+ } >+ else >+ local_fd = open(local_path, O_WRONLY | O_CREAT | O_TRUNC, >+ mode | S_IWRITE); > if (local_fd == -1) { >- error("Couldn't open local file \"%s\" for writing: %s", >- local_path, strerror(errno)); >+ if (bigger) >+ error("destination file bigger than source file"); >+ else >+ error("Couldn't open local file \"%s\" for writing: %s", >+ local_path, strerror(errno)); > do_close(conn, handle, handle_len); > buffer_free(&msg); > xfree(handle); >@@ -1062,9 +1106,9 @@ do_download(struct sftp_conn *conn, char > } > > /* Read from remote and write to local */ >- write_error = read_error = write_errno = num_req = offset = 0; >+ write_error = read_error = write_errno = num_req = 0; > max_req = 1; >- progress_counter = 0; >+ progress_counter = offset; > > if (showprogress && size != 0) > start_progress_meter(remote_path, size, &progress_counter); >@@ -1139,6 +1183,12 @@ do_download(struct sftp_conn *conn, char > write_error = 1; > max_req = 0; > } >+ else if (req->offset <= highwater) >+ highwater = req->offset + len; >+ else if (req->offset > highwater) { >+ ftruncate(local_fd, 0); >+ printf("reordered blocks detected"); >+ } > progress_counter += len; > xfree(data); > >@@ -1187,6 +1237,11 @@ do_download(struct sftp_conn *conn, char > /* Sanity check */ > if (TAILQ_FIRST(&requests) != NULL) > fatal("Transfer complete, but requests still in queue"); >+ /* Truncate at highest contiguous point to avoid holes on interrupt */ >+ if (read_error || write_error || interrupted) { >+ debug("truncating at %llu", highwater); >+ ftruncate(local_fd, highwater); >+ } > > if (read_error) { > error("Couldn't read from remote file \"%s\" : %s", >@@ -1233,6 +1288,7 @@ download_dir_internal(struct sftp_conn * > SFTP_DIRENT **dir_entries; > char *filename, *new_src, *new_dst; > mode_t mode = 0777; >+ int resume = 0; > > if (depth >= MAX_DIR_DEPTH) { > error("Maximum directory depth exceeded: %d levels", depth); >@@ -1284,7 +1340,7 @@ download_dir_internal(struct sftp_conn * > ret = -1; > } else if (S_ISREG(dir_entries[i]->a.perm) ) { > if (do_download(conn, new_src, new_dst, >- &(dir_entries[i]->a), pflag) == -1) { >+ &(dir_entries[i]->a), pflag, resume) == -1) { > error("Download of file %s to %s failed", > new_src, new_dst); > ret = -1; >@@ -1638,4 +1694,3 @@ path_append(char *p1, char *p2) > > return(ret); > } >-
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 2021
:
2165
|
2168
|
2170
|
2198
|
2199
|
2302
|
2304
|
2305
|
2313
|
2314
|
2316