Esempio n. 1
0
    def setUpTestTreeSyncAndDeleteIt(self, fixture, fileName1, options):
        writeFileTree(
            fixture.loc1,
            ["[folder],", fileName1, ".file2", ["sub", "file3 -> /usr"]])

        fixture.sync(options)
        fixture.loc1.join("[folder],").remove()
        return fixture.versionsOf("[folder],", 1, options)[0]
Esempio n. 2
0
    def test_shouldAnchorExcludeDirsCorrectlyRegardlessOfRestoreTarget(
            self, fixture):
        writeFileTree(fixture.loc1, [".", ["foo", ["bar"], ["foo", ["bar"]]]])

        options = dict(ExcludedDirs="/foo/bar")
        version = fixture.syncAndGetLatestVersion(options)

        destDir = fixture.tmpdir / "dest"
        fixture.restorePort1File("foo", version, destDir, options)
        assert os.path.isdir(str(destDir / "foo" / "bar"))
        assert not os.path.isdir(str(destDir / "bar"))
Esempio n. 3
0
    def test_shouldNotProcessListFilesOutputToEnhanceItsSpeedIfRequested(
            self, fixture):
        options = dict(ListFilesExactly=False)

        writeFileTree(fixture.loc1, ["folder", ["sub", "foo", "bar"]])
        version = fixture.getSingleVersion(additionalOptions=options)

        iterToTest(
            fixture.listPort1Files(
                "folder", version, recursively=True,
                additionalOpts=options)).shouldContainInAnyOrder(
                    "sub", "sub/foo", "sub/bar")
Esempio n. 4
0
    def test_shouldProvideOptionToCompletelyIgnoreCertainDirs(self, fixture):
        assert "ExcludedDirs" in fixture.optionNames

        backupDir, realFile, tempFile = writeFileTree(fixture.loc1, [
            ".", ["mnt", ["hdd* .", ["backup [1]"], ["data", "file [2]"]]],
            ["proc", ["1", ["attr", "exec [3]"]]]
        ])
        fixture.loc2 = backupDir

        options = dict(ExcludedDirs="""
           '/./mnt///./hdd* ./backup/' 
           /proc/1/attr""")
        fixture.sync(options)
        version = fixture.syncAndGetLatestVersion(options)

        assert len(fixture.versionsOf("mnt/hdd* ./backup", 1, options)) == 0
        assert len(fixture.versionsOf("proc/1/attr/exec", 1, options)) == 0

        if self.isMirroring:
            assert "attr" not in os.listdir(str(backupDir / "proc" / "1"))
            assert "backup" not in os.listdir(str(backupDir / "mnt" /
                                                  "hdd* ."))

        tempFile.write("foo")
        realFile.write("foo")
        fixture.restorePort1File(".", version, None, options)
        fixture.restorePort1File("mnt/hdd* .", version, None, options)
        fixture.restorePort1File("proc/1", version, None, options)
        assert tempFile.read() == "foo"
        assert realFile.read() == ""
Esempio n. 5
0
    def test_shouldTakeCustomOptionsForSyncingAndForSyncingAndRestoring(
            self, fixture):
        assert "AdditionalSyncOpts" in fixture.optionNames
        assert "AdditionalOptsBothWays" in fixture.optionNames

        options = dict(AdditionalSyncOpts="$(echo --update)",
                       AdditionalOptsBothWays="--exclude '*.o'")

        codeFile, binFile = writeFileTree(
            fixture.loc1, [".", ["src", "main.c [1]", "main.o [2]"]])
        fixture.changeMTime(codeFile, 20)
        codeFileBackup = fixture.loc2 / "src" / "main.c"
        binFileInBackup = fixture.loc2 / "src" / "main.o"

        fixture.sync(options)
        codeFileBackup.ensure(file=True)
        assert not os.path.isfile(str(binFileInBackup))
        codeFileBackup.write("//foo")
        fixture.changeMTime(codeFileBackup, 40)
        fixture.sync(options)
        binFileInBackup.write("ELF")

        codeFile.write("//bar")
        fixture.changeMTime(codeFileBackup, 60)
        fixture.restorePort1File(".", anyUTCDateTime(), None, options)
        assert codeFile.read() == "//foo"
        assert binFile.read() == ""
Esempio n. 6
0
    def test_shouldNotUseExcludedDirPathsIfTheyCantBeReanchored(self, fixture):
        testFile, = writeFileTree(fixture.loc1,
                                  [".", ["mnt", ["data", "file [1]"]]])

        options = dict(ExcludedDirs="/data")
        version = fixture.syncAndGetLatestVersion(options)

        testFile.write("bar")
        fixture.restorePort1File("mnt/data", version, None, options)
        assert testFile.read() == ""
Esempio n. 7
0
    def test_shouldInternallyResolveSymlinksOnItself(self, tmpdir):
        def inTmpdir(path):
            return str(tmpdir) + "/" + path

        writeFileTree(
            tmpdir, [".", "to-repo -> repo", ["repo", "to-without -> /home"]])

        self.assertIsWithin(inTmpdir("repo/foo"),
                            inTmpdir("to-repo"),
                            relPart="foo")
        self.assertIsWithin(inTmpdir("repo"),
                            inTmpdir("to-repo/"),
                            relPart=".")

        self.assertIsNotWithin(inTmpdir("to-repo/to-without/"),
                               inTmpdir("repo"))
        self.assertIsWithin(inTmpdir("to-repo/to-without"),
                            inTmpdir("repo"),
                            relPart="to-without")
Esempio n. 8
0
    def test_shouldIgnorePurelyStringBasedCommonPrefixesInExcludedDirsReanchoring(
            self, fixture):
        testFile, = writeFileTree(fixture.loc1,
                                  [".", ["foo", ["bar", "file [1]"]]])

        options = dict(ExcludedDirs="/foobar")
        version = fixture.syncAndGetLatestVersion(options)

        testFile.write("foo")
        fixture.restorePort1File("foo/bar", version, None, options)
        assert testFile.read() == ""
Esempio n. 9
0
    def test_shouldBeAbleToRestoreFilesDeeperWithinALoc(self, fixture):
        testFile, = writeFileTree(fixture.loc1,
                                  ["a", ["b", ["c", "file [1]"]]])
        quote = "how the poor devils beat against the walls"
        testFile.write(quote)
        version = fixture.getSingleVersion()

        testFile.remove()
        fixture.restorePort1File("a/b/c/file", version, None)
        assert testFile.read() == quote

        destFile = fixture.tmpdir / "dest"
        fixture.restorePort1File("a/b/c/file", version, str(destFile))
        assert destFile.read() == quote
Esempio n. 10
0
    def test_shouldDumpTheEntireLoc1ToACompressedTarWhenDoingAFullBackup(
            self, fixture):
        assert "Compression" in fixture.optionNames
        assert "gzip" in next(option.optionType.values
                              for option in fixture.syncer.availableOptions
                              if option.name == "Compression")

        quote = "how little, really, they departed from platitude"
        options = dict(Compression="gzip")
        fstab, = writeFileTree(fixture.loc1, [".", ["etc", "fstab [1]"]])
        fstab.write(quote)

        fixture.sync(options)

        assert archiveFileHasContents(
            fixture.loc2 / "ar1",
            lambda info: info.name.endswith("./etc/fstab"), quote)
Esempio n. 11
0
    def test_shouldUseTheIncrementsAsVersions(self, fixture):
        sameFile, topFile, folder, oldFile, newFile = writeFileTree(
            fixture.loc1, [
                ".", "samefile [1]", "file [2]",
                ["usr [3]", "oldfile [4]", "newfile [5]"]
            ])

        sameFile.write("same")
        newFile.remove()
        topFile.write("old")

        oldVersion, newVersion = self.getTwoVersions(
            fixture,
            doBetweenSyncs=lambda:
            (topFile.write("new"), newFile.write(""), oldFile.remove()))

        assert len(fixture.versionsOf("usr", 1)) == 2
        assert fixture.versionsOf("not-there", 1) == []
        assert len(fixture.versionsOf("usr/newfile", 1)) == 1

        iterToTest(fixture.listPort1Files(".",
                                          oldVersion)).shouldContainInAnyOrder(
                                              "samefile", "file", "usr/",
                                              "usr/oldfile")
        iterToTest(fixture.listPort1Files(".",
                                          newVersion)).shouldContainInAnyOrder(
                                              "samefile", "file", "usr/",
                                              "usr/newfile")

        fixture.restorePort1File("usr", oldVersion, None)
        assert os.listdir(str(folder)) == ["oldfile"]

        assert topFile.read() == "new"
        fixture.restorePort1File(".", oldVersion, None)
        assert topFile.read() == "old"

        fixture.restorePort1File(".", newVersion, None)
        assert topFile.read() == "new"
        assert os.listdir(str(folder)) == ["newfile"]
        assert set(os.listdir(str(
            fixture.loc1))) == {"usr", "samefile", "file"}