That's a bad assumption, you should always clean up after yourself.

On 21/11/2016 16:57, Val wrote:
OK, I had overlooked the fact that cleanup is important to you, which makes sense for security and to save disk space early.
TempFile, TempDir don't do the cleanup, but the OS will sooner or later.
Here is my new suggestion for a file <http://www.programming-idioms.org/idiom/138/create-temp-file/1751/go> and for a dir <http://www.programming-idioms.org/idiom/139/create-temp-directory/1757/go> :

tmpfile, err := ioutil.TempFile("", "")
checkerr(err)
defer os.Remove(tmpfile.Name())


dir, err := ioutil.TempDir("", "")
checkerr(err)
defer os.RemoveAll(dir)





On Monday, November 21, 2016 at 4:19:26 PM UTC+1, Ondrej wrote:

    That's my current code, I just wanted to double check that it's
    the proper one (ie that the cleanup actually happens), since some
    of my temp files can be fairly large.

    On Friday, 18 November 2016 15:54:36 UTC, Val wrote:

        Obtain a new temp file :
          tmpfile, err := ioutil.TempFile("", "")

        Obtain a new temp dir :
          dir, err := ioutil.TempDir("", "")

        I suggest you don't bother with cleanup.  It should work on
        any OS.

        On Friday, November 18, 2016 at 11:21:23 AM UTC+1, Ondrej wrote:

            I have a tool that generates some HTML and launches a web
            browser to display it. For this to work, I need to save
            the HTML some place and I also need to handle the file
            afterwards. The app itself doesn't persist - it generates
            the content and exits. There are thus two issues I'm
            struggling with:

            1. What is the best place for this? Do I create a folder
            in usr.HomeDir()/.appname/ and place HTML files there? Or
            do I just create tempfiles in os.TempDir? Does it make a
            difference?
            2. How do I clean up? As I said, the app does not persist
            (so I can't defer os.Remove), so either I scan the folder
            in question (before my HTML generation) and remove all
            files older than, say, a day. Or is that done for me by
            the operating system if I use os.TempDir?

            I thought I'd just use os.TempDir and let the OS handle
            it, but I'm not 100% sure the OS does clean this up on its
            own. (This will be used on Windows and Macs, maybe Linux.)
            Any insight on any of these would be greatly appreciated.

            Thanks!

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com <mailto:golang-nuts+unsubscr...@googlegroups.com>.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to