コード例 #1
0
			contents, err := ioutil.ReadFile(filepath.Join(tempDir, "received-dir", "subdir", "subdir-file.txt"))
			Expect(contents).To(BeEquivalentTo("subdir-file-contents\n"))

			contents, err = ioutil.ReadFile(filepath.Join(tempDir, "received-dir", "tempfile.txt"))
			Expect(contents).To(BeEquivalentTo("temporary-file-contents\n"))
		})

		Context("when preserving time stamps", func() {
			It("restores the access time and modification time", func() {
				timeStdin := &bytes.Buffer{}
				timeStdout := &bytes.Buffer{}
				timeStderr := &bytes.Buffer{}

				timeStdin.WriteString("T123456789 0 987654321 0\n")
				timeSession := scp.NewSession(timeStdin, timeStdout, timeStderr, true, logger)

				timeMessage := &scp.TimeMessage{}
				timeMessage.Receive(timeSession)

				stdin := &bytes.Buffer{}
				stdout := &bytes.Buffer{}
				stderr := &bytes.Buffer{}

				stdin.WriteString("D0755 0 empty-dir\n")
				stdin.WriteString("E\n")

				copier = newTestCopier(stdin, stdout, stderr, true)
				err := copier.ReceiveDirectory(tempDir, timeMessage)
				Expect(err).NotTo(HaveOccurred())
コード例 #2
0
		BeforeEach(func() {
			modificationTime := time.Unix(123456789, 12345678)
			accessTime := time.Unix(987654321, 987654321)
			os.Chtimes(tempFile, accessTime, modificationTime)

			fileInfo, ferr := os.Stat(tempFile)
			Expect(ferr).NotTo(HaveOccurred())

			timeMessage = scp.NewTimeMessage(fileInfo)
		})

		It("sends the message with the appropriate times", func() {
			stdin := bytes.NewReader([]byte{0})
			stdout := &bytes.Buffer{}
			stderr := &bytes.Buffer{}
			session := scp.NewSession(stdin, stdout, stderr, true, logger)

			err := timeMessage.Send(session)
			Expect(err).NotTo(HaveOccurred())

			Expect(stdout.String()).To(Equal("T123456789 0 987654321 0\n"))
		})

		It("writes the message before waiting for an acknowledgement", func() {
			stdin := &fake_io.FakeReader{}
			stdout := &fake_io.FakeWriter{}
			stdoutBuffer := &bytes.Buffer{}
			stderr := &bytes.Buffer{}
			session := scp.NewSession(stdin, stdout, stderr, true, logger)

			stdout.WriteStub = stdoutBuffer.Write
コード例 #3
0
ファイル: scp_test.go プロジェクト: benjaminharnett/diego-ssh
					}

					secureCopier, err = scp.NewFromCommand(command, stdin, stdout, stderr, logger)
					Expect(err).NotTo(HaveOccurred())

					done := make(chan struct{})
					go func() {
						err := secureCopier.Copy()
						Expect(err).NotTo(HaveOccurred())
						close(done)
					}()

					_, err = stdinSource.Write([]byte{0})
					Expect(err).NotTo(HaveOccurred())

					session := scp.NewSession(stdoutSource, stdinSource, nil, preserveTimestamps, logger)

					var timestampMessage *scp.TimeMessage
					if preserveTimestamps {
						timestampMessage = &scp.TimeMessage{}
						err = timestampMessage.Receive(session)
						Expect(err).NotTo(HaveOccurred())
					}

					testCopier = newTestCopier(stdoutSource, stdinSource, nil, preserveTimestamps)
					err = testCopier.ReceiveFile(targetDir, true, timestampMessage)
					Expect(err).NotTo(HaveOccurred())
					Eventually(done).Should(BeClosed())

					sourceFileInfo, err = os.Stat(generatedTextFile)
					Expect(err).NotTo(HaveOccurred())