Skip to content

Commit 9b6d770

Browse files
ragaskarCI Bot
authored andcommitted
Fix temp-path related failures.
- The fix in bd36730 (which addresses Windows Update changes that cause the root disk to run out of space in some deployment scenarios) failed for some deployments (with a "cannot find path" error originating from groot). We suspect (but are having trouble validating) that the problem is incomplete percolation of the SystemTemp env var. - This commit reverts bd36730 in favor of sym-linking C:\Windows\SystemTemp, another way of achieving the desired outcome: making sure lifecycle scripts write temp data to the ephermeral disk. A deployment configuration that failed with the changes in bd36730 completes successfully with this change. - A possible risk here is anything that might have previously _explicitly_ written to C:\Windows\SystemTemp will now appear instead in C:\var\vcap\data\tmp, which may have different permissions -- an incremental change to bd36730, which would have seen processes previously acquiring a temp dir from system calls writing to C:\var\vcap\data\tmp. Given that we would expect processes prior to the Windows Update change to _also_ have been writing to C:\var\vcap\data\tmp (via the TEMP and TMP env vars), this would not seem to overall change current behavior, although could be surprising with regards to future expectations around temp dirs. - n.b.: our test does not check that existing files in SystemTemp are removed, but we would expect this behavior to be the case (because the file system fake currently does NOT emulate this behavior, although this behavior IS expected from the concrete file system). At the moment modifying the fake to include this behavior doesn't seem to provide much benefit as this makes the test is more about fake behavior than concrete behavior.
1 parent 99cdc1a commit 9b6d770

2 files changed

Lines changed: 29 additions & 9 deletions

File tree

platform/windows_platform.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -582,6 +582,12 @@ func (p WindowsPlatform) SetupTmpDir() error {
582582
return bosherr.WrapError(err, "Creating temp dir")
583583
}
584584

585+
systemTemp := os.TempDir()
586+
err = p.fs.Symlink(boshTmpDir, systemTemp)
587+
if err != nil {
588+
return bosherr.WrapError(err, fmt.Sprintf("Creating symlink from %s to %s", systemTemp, boshTmpDir))
589+
}
590+
585591
err = os.Setenv("TMP", boshTmpDir)
586592
if err != nil {
587593
return bosherr.WrapError(err, "Setting TMP")
@@ -592,11 +598,6 @@ func (p WindowsPlatform) SetupTmpDir() error {
592598
return bosherr.WrapError(err, "Setting TEMP")
593599
}
594600

595-
err = os.Setenv("SystemTemp", boshTmpDir)
596-
if err != nil {
597-
return bosherr.WrapError(err, "Setting SystemTemp")
598-
}
599-
600601
return nil
601602
}
602603

platform/windows_platform_test.go

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -172,9 +172,14 @@ var _ = Describe("WindowsPlatform", func() {
172172

173173
Describe("SetupTmpDir", func() {
174174
var (
175-
OrigTMP = os.Getenv("TMP")
176-
OrigTEMP = os.Getenv("TEMP")
175+
OrigTMP = os.Getenv("TMP")
176+
OrigTEMP = os.Getenv("TEMP")
177+
systemTemp = os.TempDir()
177178
)
179+
BeforeEach(func() {
180+
err := fs.MkdirAll(systemTemp, 0755)
181+
Expect(err).NotTo(HaveOccurred())
182+
})
178183
AfterEach(func() {
179184
os.Setenv("TMP", OrigTMP) //nolint:errcheck
180185
os.Setenv("TEMP", OrigTEMP) //nolint:errcheck
@@ -197,14 +202,28 @@ var _ = Describe("WindowsPlatform", func() {
197202
Expect(err.Error()).To(ContainSubstring("fake-mkdir-error"))
198203
})
199204

200-
It("sets TMP, TEMP, and SystemTemp environment variables so that children of this process will use new temp dir", func() {
205+
It("sets TMP, TEMP environment variables so that children of this process will use new temp dir", func() {
201206
err := platform.SetupTmpDir()
202207
Expect(err).NotTo(HaveOccurred())
203208

204209
fakeTmpDir := filepath.FromSlash("/fake-dir/data/tmp")
205210
Expect(os.Getenv("TMP")).To(Equal(fakeTmpDir))
206211
Expect(os.Getenv("TEMP")).To(Equal(fakeTmpDir))
207-
Expect(os.Getenv("SystemTemp")).To(Equal(fakeTmpDir))
212+
})
213+
214+
It("symlinks os.TempDir to $base-dir/data/tmp", func() {
215+
fileStats := fs.GetFileTestStat(systemTemp)
216+
Expect(fileStats).NotTo(BeNil())
217+
Expect(fileStats.FileType).To(Equal(fakesys.FakeFileTypeDir))
218+
219+
err := platform.SetupTmpDir()
220+
Expect(err).NotTo(HaveOccurred())
221+
222+
fileStats = fs.GetFileTestStat(systemTemp)
223+
Expect(fileStats).NotTo(BeNil())
224+
Expect(fileStats.FileType).To(Equal(fakesys.FakeFileTypeSymlink))
225+
226+
Expect(fileStats.SymlinkTarget).To(Equal("/fake-dir/data/tmp"))
208227
})
209228

210229
It("returns error if setting TMPDIR errs", func() {

0 commit comments

Comments
 (0)