mirror of
https://github.com/tailscale/tailscale.git
synced 2025-03-23 01:31:06 +00:00
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>
This commit is contained in:
parent
b1867eb23f
commit
8f948638c5
@ -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…
x
Reference in New Issue
Block a user