diff --git a/machinery/src/cloud/kerberos_vault.go b/machinery/src/cloud/kerberos_vault.go index 861fdce..8f0dd4c 100644 --- a/machinery/src/cloud/kerberos_vault.go +++ b/machinery/src/cloud/kerberos_vault.go @@ -35,10 +35,15 @@ func UploadKerberosVault(configuration *models.Configuration, fileName string) ( // This can happen when the file was already removed (e.g. cleanup, or an // earlier successful upload). Skip it so the watcher drops the marker // instead of retrying indefinitely. - if _, err := os.Stat("data/recordings/" + fileName); err != nil { + info, err := os.Stat("data/recordings/" + fileName) + if err != nil { log.Log.Info("UploadKerberosVault: skipping " + fileName + ", file doesn't exist anymore") return false, false, nil } + if info.Size() == 0 { + log.Log.Warning("UploadKerberosVault: skipping " + fileName + ", recording is empty") + return false, false, nil + } // timestamp_microseconds_instanceName_regionCoordinates_numberOfChanges_token // 1564859471_6-474162_oprit_577-283-727-375_1153_27.mp4 diff --git a/machinery/src/cloud/tus_client_test.go b/machinery/src/cloud/tus_client_test.go index 5bfca63..68a42ca 100644 --- a/machinery/src/cloud/tus_client_test.go +++ b/machinery/src/cloud/tus_client_test.go @@ -264,6 +264,36 @@ func testVault(uri string) models.KStorage { } } +func TestUploadKerberosVaultSkipsEmptyRecording(t *testing.T) { + fileName := "1787015373_3-654_office-camera17_0-0-0-0_-1_1960.mp4" + withRecording(t, fileName, nil) + + requestCount := 0 + server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + requestCount++ + w.WriteHeader(http.StatusInternalServerError) + })) + defer server.Close() + + vault := testVault(server.URL) + configuration := &models.Configuration{Config: models.Config{ + Key: "device-key", + KStorage: &vault, + KStorageSecondary: &models.KStorage{}, + }} + + uploaded, configured, err := UploadKerberosVault(configuration, fileName) + if err != nil { + t.Fatalf("UploadKerberosVault() error = %v", err) + } + if uploaded || configured { + t.Fatalf("UploadKerberosVault() uploaded/configured = %v/%v, want false/false", uploaded, configured) + } + if requestCount != 0 { + t.Fatalf("Vault received %d requests, want 0", requestCount) + } +} + func TestUploadVaultResumable_HappyPath(t *testing.T) { srv := newFakeTus() ts := httptest.NewServer(srv)