Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot find Results.xml output file if current directory is changed. #1295

Closed
theprash opened this issue Jul 11, 2016 · 3 comments
Closed

Cannot find Results.xml output file if current directory is changed. #1295

theprash opened this issue Jul 11, 2016 · 3 comments

Comments

@theprash
Copy link
Contributor

Description

Changing the current working directory breaks XML logging.

Repro steps

  • Start a build script via CruiseControl or specifying an output file.
  • In the script, change the current directory with System.IO.Directory.SetCurrentDirectory.
  • Perform some action that would log to the output file.

Expected behavior

The log message is added to the file in the original location, regardless of the current directory.

Actual behavior

Throws:

System.IO.DirectoryNotFoundException: Could not find a part of the path 'C:\xxx\xxx\output\Results.xml'

Notes

The stack trace points here. xmlOutputFile comes from a parameter that defaults to a relative path. Turning this into an absolute path early on should fix the problem.

@theprash
Copy link
Contributor Author

My proposed fix above does seem to work. I'll make a PR soon.

@theprash
Copy link
Contributor Author

After making my fix I was still getting another error:

Error: System.IO.IOException: The process cannot access the file 'C:\temp\fake-test\output\Results.xml' because it is being used by another process.

I found out that this was because TraceListener.fs was being loaded twice. That is, there were two separate points where a stack trace contained:

at <StartupCode$FakeLib>.$Fake.TraceListener..cctor() in C:\Users\Prash\dev\FAKE\src\app\FakeLib\TraceListener.fs:line 151

So all of the top level actions and definitions in TraceListener.fs, were being evaluated twice and their side-effects executed twice. So the line if hasBuildParam "logfile" || buildServer = CCNet then addXmlListener xmlOutputFile was adding two XML listeners on the same file, causing the IOException.

I found that this only happened in Debug mode and everything was fine in Release mode. Is this a known thing? It doesn't affect my original reported bug or the fix so I'll submit a PR.

@theprash
Copy link
Contributor Author

My test setup to reproduce this:

fake-test.fsx:

#r @"C:\Users\Prash\dev\FAKE\build\FakeLib.dll"

open Fake
open System.IO

buildServer |> printfn "%A"

Target "Testing" (fun _ ->
    trace "1"
    let orig = Directory.GetCurrentDirectory()
    Directory.SetCurrentDirectory @"C:\"
    trace "2"
    Directory.SetCurrentDirectory orig
)

RunTargetOrDefault "Testing"

run.ps1:

$env:CCNETLABEL = 1
C:\Users\Prash\dev\FAKE\build\FAKE.exe fake-test.fsx

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant