question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Request for `using (TempDirectory(x))` syntax

See original GitHub issue

Instead of this:

    .Does(() =>
{
    var stagingDir = Directory("path");
    CreateDirectory(stagingDir);
    try
    {
        CleanDirectory(stagingDir);
        CopyFiles("glob", stagingDir);
        // Run some non-globbable tool on stagingDir
    }
    finally
    {
        DeleteDirectory(stagingDir, true);
    }
    // stagingDir is gone
}

I would like to be able to do this:

    .Does(() =>
{
    var stagingDir = Directory("path");
    using (TempDirectory(stagingDir))
    {
        CopyFiles("glob", stagingDir);
        // Run some non-globbable tool on stagingDir
    }
    // stagingDir is gone
}

Willing to PR if you like this idea.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:2
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
patriksvenssoncommented, Dec 28, 2016

@jnm2 The problem with something like using(WorkingDirectory(x)) is that it would manipulate global state. This would make it problematic to do things like task parallelisation. So I think that we wait with a PR until we have way of solving this.

0reactions
jnm2commented, Dec 28, 2016

@patriksvensson Oh good! I didn’t know parallelization was a goal, but I’m glad it is. I wonder if using AsyncLocal for the implementation would be all that’s needed?

Read more comments on GitHub >

github_iconTop Results From Across the Web

bash - How to create a temporary directory?
Use mktemp -d . It creates a temporary directory with a random name and makes sure that file doesn't already exist. You need...
Read more >
Providing option to override temp location would be a great ...
When I try to recreate a tempdir using check=TRUE , a new tempdir is created, but callr still points back to the old...
Read more >
Process of Creating Directory and Temp ...
This article explains you how to create primary directory and temporary directory in node.js step by step process. Find a detailed analysis ...
Read more >
Transient data storage for different users - how to? - shiny
Basically the user uploads some data, it will be interactively converted by the user and in the end a lot of plots and...
Read more >
Working and unit testing with temporary files in Java
In this article, I examine the use of temporary files in Java. ... two major versions—JUnit 4.x and 5.x—I provide code for both...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found