public SumStruct ReceiveSums(ClientInfo cInfo) { IOStream f = cInfo.IoStream; SumStruct s = new SumStruct(); int i; int offset = 0; ReadSumHead(cInfo, ref s); s.sums = null; if (options.verbose > 3) { Log.WriteLine("count=" + s.count + " n=" + s.bLength + " rem=" + s.remainder); } if (s.count == 0) { return(s); } s.sums = new SumBuf[s.count]; for (i = 0; i < s.count; i++) { s.sums[i] = new SumBuf(); s.sums[i].sum1 = (UInt32)f.readInt(); s.sums[i].sum2 = f.ReadBuf(s.s2Length); s.sums[i].offset = offset; s.sums[i].flags = 0; if (i == s.count - 1 && s.remainder != 0) { s.sums[i].len = s.remainder; } else { s.sums[i].len = s.bLength; } offset += (int)s.sums[i].len; if (options.verbose > 3) { Log.WriteLine("chunk[" + i + "] len=" + s.sums[i].len); } } s.fLength = offset; return(s); }
public int SimpleReceiveToken(IOStream f, ref byte[] data, int offset) { int n; if (residue == 0) { int i = f.readInt(); if (i <= 0) return i; residue = i; } n = Math.Min(Match.CHUNK_SIZE,residue); residue -= n; data = f.ReadBuf(n); return n; }
public int SimpleReceiveToken(IOStream f, ref byte[] data, int offset) { int n; if (residue == 0) { int i = f.readInt(); if (i <= 0) { return(i); } residue = i; } n = Math.Min(Match.CHUNK_SIZE, residue); residue -= n; data = f.ReadBuf(n); return(n); }
public FileStruct receiveFileEntry(UInt32 flags, ClientInfo cInfo) { if (cInfo == null) { lastName = ""; return(null); } IOStream f = cInfo.IoStream; int l1 = 0, l2 = 0; if ((flags & Options.XMIT_SAME_NAME) != 0) { l1 = f.readByte(); } if ((flags & Options.XMIT_LONG_NAME) != 0) { l2 = f.readInt(); } else { l2 = f.readByte(); } if (l2 >= Options.MAXPATHLEN - l1) { MainClass.Exit("overflow: lastname=" + lastName, cInfo); } string thisName = lastName.Substring(0, l1); thisName += f.ReadSBuf(l2); lastName = thisName; thisName = Util.cleanFileName(thisName, false); if (options.sanitizePath) { thisName = Util.sanitizePath(thisName, "", 0); } string baseName = ""; string dirName = ""; if (thisName.LastIndexOf("/") != -1) { baseName = Path.GetFileName(thisName); dirName = FileSystem.Directory.GetDirectoryName(thisName).Replace(@"\", "/").Replace(":", ""); } else { baseName = thisName; dirName = null; } Int64 fileLength = f.ReadLongInt(); if ((flags & Options.XMIT_SAME_TIME) == 0) { modTime = DateTime.FromFileTime(f.readInt()); } if ((flags & Options.XMIT_SAME_MODE) == 0) { mode = (UInt32)f.readInt(); } if (options.preserveUID && (flags & Options.XMIT_SAME_UID) == 0) { int uid = f.readInt(); } if (options.preserveGID && (flags & Options.XMIT_SAME_GID) == 0) { int gid = f.readInt(); } byte[] sum = new byte[0]; if (options.alwaysChecksum && !Util.S_ISDIR(mode)) { sum = new byte[CheckSum.MD4_SUM_LENGTH]; sum = f.ReadBuf(options.protocolVersion < 21 ? 2 : CheckSum.MD4_SUM_LENGTH); } FileStruct fs = new FileStruct(); fs.length = (int)fileLength; fs.baseName = baseName; fs.dirName = dirName; fs.sum = sum; fs.mode = mode; fs.modTime = modTime; fs.flags = flags; return(fs); }
public bool ReceiveData(ClientInfo cInfo, string fileNameR, Stream fdR, long sizeR, string fileName, Stream fd, int totalSize) { IOStream f = cInfo.IoStream; byte[] file_sum1 = new byte[CheckSum.MD4_SUM_LENGTH]; byte[] file_sum2 = new byte[CheckSum.MD4_SUM_LENGTH]; byte[] data = new byte[Match.CHUNK_SIZE]; SumStruct sum = new SumStruct(); MapFile mapBuf = null; Sender sender = new Sender(options); sender.ReadSumHead(cInfo, ref sum); int offset = 0; UInt32 len; if (fdR != null && sizeR > 0) { int mapSize = (int)Math.Max(sum.bLength * 2, 16 * 1024); mapBuf = new MapFile(fdR, (int)sizeR, mapSize, (int)sum.bLength); if (options.verbose > 2) { Log.WriteLine("recv mapped " + fileNameR + " of size " + sizeR); } ; } Sum s = new Sum(options); s.Init(options.checksumSeed); int i; Token token = new Token(options); while ((i = token.ReceiveToken(f, ref data, 0)) != 0) { if (options.doProgress) { Progress.ShowProgress(offset, totalSize); } if (i > 0) { if (options.verbose > 3) { Log.WriteLine("data recv " + i + " at " + offset); } Options.stats.literalData += i; s.Update(data, 0, i); if (fd != null && FileIO.WriteFile(fd, data, 0, i) != i) { goto report_write_error; } offset += i; continue; } i = -(i + 1); int offset2 = (int)(i * sum.bLength); len = sum.bLength; if (i == sum.count - 1 && sum.remainder != 0) { len = sum.remainder; } Options.stats.matchedData += len; if (options.verbose > 3) { Log.WriteLine("chunk[" + i + "] of size " + len + " at " + offset2 + " offset=" + offset); } byte[] map = null; int off = 0; if (mapBuf != null) { off = mapBuf.MapPtr(offset2, (int)len); map = mapBuf.p; token.SeeToken(map, offset, (int)len); s.Update(map, off, (int)len); } if (options.inplace) { if (offset == offset2 && fd != null) { offset += (int)len; if (fd.Seek(len, SeekOrigin.Current) != offset) { MainClass.Exit("seek failed on " + Util.fullFileName(fileName), cInfo); } continue; } } if (fd != null && FileIO.WriteFile(fd, map, off, (int)len) != (int)len) { goto report_write_error; } offset += (int)len; } if (options.doProgress) { Progress.EndProgress(totalSize); } if (fd != null && offset > 0 && FileIO.SparseEnd(fd) != 0) { MainClass.Exit("write failed on " + Util.fullFileName(fileName), cInfo); } file_sum1 = s.End(); if (mapBuf != null) { mapBuf = null; } file_sum2 = f.ReadBuf(CheckSum.MD4_SUM_LENGTH); if (options.verbose > 2) { Log.WriteLine("got fileSum"); } if (fd != null && Util.MemCmp(file_sum1, 0, file_sum2, 0, CheckSum.MD4_SUM_LENGTH) != 0) { return(false); } return(true); report_write_error: { MainClass.Exit("write failed on " + Util.fullFileName(fileName), cInfo); } return(true); }