diff options
author | Andrew Tridgell <tridge@samba.org> | 1998-05-15 14:00:12 +0000 |
---|---|---|
committer | Andrew Tridgell <tridge@samba.org> | 1998-05-15 14:00:12 +0000 |
commit | 3e607d23543f0f3fb7b72953b89334071540667f (patch) | |
tree | 6a76165419533c297739ebbd78bec86188309e72 /util.c | |
parent | a6801c397732a55d2f9f477a360db6fc09bb1c3d (diff) | |
download | rsync-3e607d23543f0f3fb7b72953b89334071540667f.tar.gz rsync-3e607d23543f0f3fb7b72953b89334071540667f.tar.bz2 rsync-3e607d23543f0f3fb7b72953b89334071540667f.zip |
got rid of "EOF in map_ptr" problem. If a file shrinks mid transfer
then we supply a zero filled buffer at the end and rely on the
checksum to cause a retry. This is really the best we can do as there
is no correct semantics for copying a changing file!
Diffstat (limited to 'util.c')
-rw-r--r-- | util.c | 63 |
1 files changed, 34 insertions, 29 deletions
@@ -60,44 +60,49 @@ struct map_struct *map_file(int fd,OFF_T len) char *map_ptr(struct map_struct *map,OFF_T offset,int len) { - int nread = -2; + int nread; - if (map->map) - return map->map+offset; + if (map->map) + return map->map+offset; - if (len == 0) - return NULL; + if (len == 0) + return NULL; - if (len > (map->size-offset)) - len = map->size-offset; + if (len > (map->size-offset)) + len = map->size-offset; - if (offset >= map->p_offset && - offset+len <= map->p_offset+map->p_len) { - return (map->p + (offset - map->p_offset)); - } + if (offset >= map->p_offset && + offset+len <= map->p_offset+map->p_len) { + return (map->p + (offset - map->p_offset)); + } - len = MAX(len,CHUNK_SIZE); - if (len > (map->size-offset)) - len = map->size-offset; + len = MAX(len,CHUNK_SIZE); + if (len > (map->size-offset)) + len = map->size-offset; - if (len > map->p_size) { - if (map->p) free(map->p); - map->p = (char *)malloc(len); - if (!map->p) out_of_memory("map_ptr"); - map->p_size = len; - } + if (len > map->p_size) { + if (map->p) free(map->p); + map->p = (char *)malloc(len); + if (!map->p) out_of_memory("map_ptr"); + map->p_size = len; + } - if (do_lseek(map->fd,offset,SEEK_SET) != offset || - (nread=read(map->fd,map->p,len)) != len) { - rprintf(FERROR,"EOF in map_ptr! (offset=%d len=%d nread=%d errno=%d)\n", - (int)offset, len, nread, errno); - exit_cleanup(1); - } + map->p_offset = offset; + map->p_len = len; - map->p_offset = offset; - map->p_len = len; + if (do_lseek(map->fd,offset,SEEK_SET) != offset) { + rprintf(FERROR,"lseek failed in map_ptr\n"); + exit_cleanup(1); + } - return map->p; + if ((nread=read(map->fd,map->p,len)) != len) { + if (nread < 0) nread = 0; + /* the best we can do is zero the buffer - the file + has changed mid transfer! */ + memset(map->p+nread, 0, len - nread); + } + + return map->p; } |