Пример #1
0
		_, err = rand.Read(fileContents)
		Expect(err).NotTo(HaveOccurred())

		err = ioutil.WriteFile(tempFile, fileContents, 0400)
		Expect(err).NotTo(HaveOccurred())
	})

	AfterEach(func() {
		os.RemoveAll(tempDir)
	})

	Context("when creating a time message from file information", func() {
		var (
			timeMessage *scp.TimeMessage

			expectedModificationTime time.Time
			expectedAccessTime       time.Time
		)

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

			expectedAccessTime, ferr = atime.AccessTime(fileInfo)
			Expect(ferr).NotTo(HaveOccurred())

			expectedModificationTime = fileInfo.ModTime()

			timeMessage = scp.NewTimeMessage(fileInfo)
		})
Пример #2
0
					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())
				})