sharedpullerstate_test.go 945 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  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 := t.TempDir()
  17. if err := os.Chmod(tmpDir, 0555); err != nil {
  18. t.Fatal(err)
  19. }
  20. defer os.Chmod(tmpDir, 0755)
  21. s := sharedPullerState{
  22. fs: fs.NewFilesystem(fs.FilesystemTypeBasic, tmpDir),
  23. tempName: ".temp_name",
  24. mut: sync.NewRWMutex(),
  25. }
  26. fd, err := s.tempFile()
  27. if err != nil {
  28. t.Fatal(err)
  29. }
  30. if fd == nil {
  31. t.Fatal("Unexpected nil fd")
  32. }
  33. s.fail(nil)
  34. s.finalClose()
  35. }