taildrop: minor cleanups and fixes (#9786)

Perform the same m==nil check in Manager.{PartialFiles,HashPartialFile}
as we do in the other methods.

Fix HashPartialFile is properly handle a length of -1.

Updates tailscale/corp#14772

Signed-off-by: Joe Tsai <joetsai@digital-static.net>
pull/9792/head
Joe Tsai 7 months ago committed by GitHub
parent b1867eb23f
commit 8f948638c5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -72,8 +72,8 @@ func hexAppendEncode(dst, src []byte) []byte {
// PartialFiles returns a list of partial files in [Handler.Dir]
// that were sent (or is actively being sent) by the provided id.
func (m *Manager) PartialFiles(id ClientID) (ret []string, err error) {
if m.Dir == "" {
return ret, ErrNoTaildrop
if m == nil || m.Dir == "" {
return nil, ErrNoTaildrop
}
if m.DirectFileMode && m.AvoidFinalRename {
return nil, nil // resuming is not supported for users that peek at our file structure
@ -109,7 +109,7 @@ func (m *Manager) PartialFiles(id ClientID) (ret []string, err error) {
// If [FileHashes.Length] is less than length and no error occurred,
// then it implies that all remaining content in the file has been hashed.
func (m *Manager) HashPartialFile(id ClientID, baseName string, offset, length int64) (FileChecksums, error) {
if m.Dir == "" {
if m == nil || m.Dir == "" {
return FileChecksums{}, ErrNoTaildrop
}
if m.DirectFileMode && m.AvoidFinalRename {
@ -138,7 +138,10 @@ func (m *Manager) HashPartialFile(id ClientID, baseName string, offset, length i
BlockSize: blockSize,
}
b := make([]byte, blockSize) // TODO: Pool this?
r := io.LimitReader(f, length)
r := io.Reader(f)
if length >= 0 {
r = io.LimitReader(f, length)
}
for {
switch n, err := io.ReadFull(r, b); {
case err != nil && err != io.EOF && err != io.ErrUnexpectedEOF:

Loading…
Cancel
Save