sharedpullerstate_test.go 976 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. // Copyright (C) 2014 The Syncthing Authors.
  2. //
  3. // This Source Code Form is subject to the terms of the Mozilla Public
  4. // License, v. 2.0. If a copy of the MPL was not distributed with this file,
  5. // You can obtain one at https://mozilla.org/MPL/2.0/.
  6. package model
  7. import (
  8. "os"
  9. "testing"
  10. "github.com/syncthing/syncthing/lib/fs"
  11. "github.com/syncthing/syncthing/lib/sync"
  12. )
  13. // Test creating temporary file inside read-only directory
  14. func TestReadOnlyDir(t *testing.T) {
  15. // Create a read only directory, clean it up afterwards.
  16. tmpDir := createTmpDir()
  17. defer os.RemoveAll(tmpDir)
  18. if err := os.Chmod(tmpDir, 0555); err != nil {
  19. t.Fatal(err)
  20. }
  21. defer os.Chmod(tmpDir, 0755)
  22. s := sharedPullerState{
  23. fs: fs.NewFilesystem(fs.FilesystemTypeBasic, tmpDir),
  24. tempName: ".temp_name",
  25. mut: sync.NewRWMutex(),
  26. }
  27. fd, err := s.tempFile()
  28. if err != nil {
  29. t.Fatal(err)
  30. }
  31. if fd == nil {
  32. t.Fatal("Unexpected nil fd")
  33. }
  34. s.fail(nil)
  35. s.finalClose()
  36. }