فهرست منبع

lib/db, lib/discover: Minor cleanup (#8217)

greatroar 3 سال پیش
والد
کامیت
26eaedc491
3فایلهای تغییر یافته به همراه4 افزوده شده و 26 حذف شده
  1. 2 2
      lib/db/db_test.go
  2. 0 14
      lib/db/structs.go
  3. 2 10
      lib/discover/global.go

+ 2 - 2
lib/db/db_test.go

@@ -133,13 +133,13 @@ var (
 	update0to3Folder             = "UpdateSchema0to3"
 	invalid                      = "invalid"
 	slashPrefixed                = "/notgood"
-	haveUpdate0to3               map[protocol.DeviceID]fileList
+	haveUpdate0to3               map[protocol.DeviceID][]protocol.FileInfo
 )
 
 func init() {
 	remoteDevice0, _ = protocol.DeviceIDFromString("AIR6LPZ-7K4PTTV-UXQSMUU-CPQ5YWH-OEDFIIQ-JUG777G-2YQXXR5-YD6AWQR")
 	remoteDevice1, _ = protocol.DeviceIDFromString("I6KAH76-66SLLLB-5PFXSOA-UFJCDZC-YAOMLEK-CP2GB32-BV5RQST-3PSROAU")
-	haveUpdate0to3 = map[protocol.DeviceID]fileList{
+	haveUpdate0to3 = map[protocol.DeviceID][]protocol.FileInfo{
 		protocol.LocalDeviceID: {
 			protocol.FileInfo{Name: "a", Version: protocol.Vector{Counters: []protocol.Counter{{ID: myID, Value: 1000}}}, Blocks: genBlocks(1)},
 			protocol.FileInfo{Name: slashPrefixed, Version: protocol.Vector{Counters: []protocol.Counter{{ID: myID, Value: 1000}}}, Blocks: genBlocks(1)},

+ 0 - 14
lib/db/structs.go

@@ -512,17 +512,3 @@ func (fv FileVersion) copy() FileVersion {
 	n.InvalidDevices = append([][]byte{}, fv.InvalidDevices...)
 	return n
 }
-
-type fileList []protocol.FileInfo
-
-func (fl fileList) Len() int {
-	return len(fl)
-}
-
-func (fl fileList) Swap(a, b int) {
-	fl[a], fl[b] = fl[b], fl[a]
-}
-
-func (fl fileList) Less(a, b int) bool {
-	return fl[a].Name < fl[b].Name
-}

+ 2 - 10
lib/discover/global.go

@@ -420,26 +420,18 @@ type contextClient struct {
 }
 
 func (c *contextClient) Get(ctx context.Context, url string) (*http.Response, error) {
-	// For <go1.13 compatibility. Use the following commented line once that
-	// isn't required anymore.
-	// req, err := http.NewRequestWithContext(ctx, "GET", url, nil)
-	req, err := http.NewRequest("GET", url, nil)
+	req, err := http.NewRequestWithContext(ctx, "GET", url, nil)
 	if err != nil {
 		return nil, err
 	}
-	req.Cancel = ctx.Done()
 	return c.Client.Do(req)
 }
 
 func (c *contextClient) Post(ctx context.Context, url, ctype string, data io.Reader) (*http.Response, error) {
-	// For <go1.13 compatibility. Use the following commented line once that
-	// isn't required anymore.
-	// req, err := http.NewRequestWithContext(ctx, "POST", url, data)
-	req, err := http.NewRequest("POST", url, data)
+	req, err := http.NewRequestWithContext(ctx, "POST", url, data)
 	if err != nil {
 		return nil, err
 	}
-	req.Cancel = ctx.Done()
 	req.Header.Set("Content-Type", ctype)
 	return c.Client.Do(req)
 }