sharedpullerstate_test.go 1004 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. os.Mkdir("testdata/read_only_dir", 0555)
  17. defer func() {
  18. os.Chmod("testdata/read_only_dir", 0755)
  19. os.RemoveAll("testdata/read_only_dir")
  20. }()
  21. s := sharedPullerState{
  22. fs: fs.NewFilesystem(fs.FilesystemTypeBasic, "testdata"),
  23. tempName: "read_only_dir/.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("Test done", nil)
  34. s.finalClose()
  35. }