* ftpfs.c (ftpfs_file_store): Make sure we write() all read() data.

Check fstat() return value.
This commit is contained in:
Andrew V. Samoilov 2005-01-19 09:17:38 +00:00
parent 0464629b20
commit f4cb47b95d
2 changed files with 57 additions and 47 deletions

View File

@ -1,3 +1,8 @@
2005-01-19 Andrew V. Samoilov <sav@bcs.zp.ua>
* ftpfs.c (ftpfs_file_store): Make sure we write() all read() data.
Check fstat() return value.
2005-01-07 Roland Illig <roland.illig@gmx.de>
* extfs/urar.in: Fixed some quoting issues.
@ -103,11 +108,12 @@
2004-10-29 Pavel S. Shirshov <me@pavelsh.pp.ru>
* extfs/iso9660.in (mcisofs_list): Fix regular expression for stripping
of file name. Use autotools macro for awk instead full path.
of file name. Use autotools macro for awk instead of full path.
2004-10-28 Leonard den Ottolander <leonard * den ottolander nl>
* extfs/iso9660.in (mcisofs_list): Fix stripping of file name in awk code.
* extfs/iso9660.in (mcisofs_list): Fix stripping of file name
in awk code.
2004-10-28 Andrew V. Samoilov <sav@bcs.zp.ua>
@ -120,7 +126,7 @@
2004-10-27 Leonard den Ottolander <leonard * den ottolander nl>
* tar.c tar_read_header(): q should not point to a static string.
* tar.c (tar_read_header): q should not point to a static string.
Canonicalize q.
* extfs/iso9660.in: Fix quoting issues.
@ -200,7 +206,7 @@
2004-10-05 Miroslav Rudisin <miero+gnu@atrey.karlin.mff.cuni.cz>
* utilvfs.c(vfs_split_url): Add support for '@' in username.
* utilvfs.c (vfs_split_url): Add support for '@' in username.
2004-09-27 Andrew V. Samoilov <sav@bcs.zp.ua>
@ -217,12 +223,13 @@
* ftpfs.c (ftpfs_find_machine): Added const qualifier.
* mcserv.c (do_auth): Likewise.
* utilvfs.c (is_month): Likewise. (is_time): Likewise.
* utilvfs.c (is_month): Likewise.
(is_time): Likewise.
(is_week): Likewise.
* vfs.c (_vfs_get_class): Added const qualifier.
(vfs_prefix_to_class): Added a string length parameter to
reduce the use of g_strdup. (vfs_split): Changes due to the
new string length parameter.
reduce the use of g_strdup().
(vfs_split): Changes due to the new string length parameter.
2004-09-25 Pavel S. Shirshov <me@pavelsh.pp.ru>

View File

@ -1292,10 +1292,11 @@ ftpfs_dir_load (struct vfs_class *me, struct vfs_s_inode *dir, char *remote_path
}
static int
ftpfs_file_store(struct vfs_class *me, struct vfs_s_fh *fh, char *name, char *localname)
ftpfs_file_store (struct vfs_class *me, struct vfs_s_fh *fh, char *name,
char *localname)
{
int h, sock, n;
off_t total;
int h, sock, n_read, n_written;
off_t n_stored;
#ifdef HAVE_STRUCT_LINGER_L_LINGER
struct linger li;
#else
@ -1303,69 +1304,71 @@ ftpfs_file_store(struct vfs_class *me, struct vfs_s_fh *fh, char *name, char *lo
#endif
char buffer[8192];
struct stat s;
char *w_buf;
struct vfs_s_super *super = FH_SUPER;
h = open(localname, O_RDONLY);
h = open (localname, O_RDONLY);
if (h == -1)
ERRNOR (EIO, -1);
fstat(h, &s);
sock = ftpfs_open_data_connection(me, super, fh->u.ftp.append ? "APPE" : "STOR", name, TYPE_BINARY, 0);
if (sock < 0) {
close(h);
ERRNOR (EIO, -1);
sock =
ftpfs_open_data_connection (me, super,
fh->u.ftp.append ? "APPE" : "STOR", name,
TYPE_BINARY, 0);
if (sock < 0 || fstat (h, &s) == -1) {
close (h);
return -1;
}
#ifdef HAVE_STRUCT_LINGER_L_LINGER
li.l_onoff = 1;
li.l_linger = 120;
setsockopt(sock, SOL_SOCKET, SO_LINGER, (char *) &li, sizeof(li));
setsockopt (sock, SOL_SOCKET, SO_LINGER, (char *) &li, sizeof (li));
#else
setsockopt(sock, SOL_SOCKET, SO_LINGER, &flag_one, sizeof (flag_one));
setsockopt (sock, SOL_SOCKET, SO_LINGER, &flag_one, sizeof (flag_one));
#endif
total = 0;
enable_interrupt_key();
n_stored = 0;
enable_interrupt_key ();
while (1) {
while ((n = read(h, buffer, sizeof(buffer))) < 0) {
while ((n_read = read (h, buffer, sizeof (buffer))) == -1) {
if (errno == EINTR) {
if (got_interrupt()) {
if (got_interrupt ()) {
ftpfs_errno = EINTR;
goto error_return;
}
else
} else
continue;
}
ftpfs_errno = errno;
goto error_return;
}
if (n == 0)
if (n_read == 0)
break;
while (write(sock, buffer, n) < 0) {
if (errno == EINTR) {
if (got_interrupt()) {
ftpfs_errno = EINTR;
goto error_return;
}
else
n_stored += n_read;
w_buf = buffer;
while ((n_written = write (sock, w_buf, n_read)) != n_read) {
if (n_written == -1) {
if (errno == EINTR && !got_interrupt ()) {
continue;
}
ftpfs_errno = errno;
goto error_return;
}
ftpfs_errno = errno;
goto error_return;
w_buf += n_written;
n_read -= n_written;
}
total += n;
print_vfs_message(_("ftpfs: storing file %lu (%lu)"),
(unsigned long) total, (unsigned long) s.st_size);
print_vfs_message (_("ftpfs: storing file %lu (%lu)"),
(unsigned long) n_stored, (unsigned long) s.st_size);
}
disable_interrupt_key();
close(sock);
close(h);
disable_interrupt_key ();
close (sock);
close (h);
if (ftpfs_get_reply (me, SUP.sock, NULL, 0) != COMPLETE)
ERRNOR (EIO, -1);
ERRNOR (EIO, -1);
return 0;
error_return:
disable_interrupt_key();
close(sock);
close(h);
ftpfs_get_reply(me, SUP.sock, NULL, 0);
error_return:
disable_interrupt_key ();
close (sock);
close (h);
ftpfs_get_reply (me, SUP.sock, NULL, 0);
return -1;
}