Re: [go-nuts] Re: Best practice when creating temporary files

2016-11-21 Thread Steven Hartland
Where I was going was that's an assumption based on OS specifics; some do e.g. most Linux flavors but not all OS's do at least by default, so its best to avoid the assumption that it will happen. Absolutely agree that crashes happen, but this thread was about standard cleanup after a program which

[go-nuts] Re: Best practice when creating temporary files

2016-11-21 Thread notcarl via golang-nuts
One approach that I use is to make new invocations of the program try to clean up after older ones. For example, if you name your temp directories with a particular pattern, you can delete old directories on start up. Ideally you _should_ try to clean up in the same process, but it isn't alwa

Re: [go-nuts] Re: Best practice when creating temporary files

2016-11-21 Thread 'Thomas Bushnell, BSG' via golang-nuts
It's fine to try, but you should design your entire system with the assumption that your program may crash at any moment and leave something around. This is why the OS cleans up /tmp. Thomas On Mon, Nov 21, 2016 at 9:01 AM Steven Hartland wrote: > That's a bad assumption, you should always clea

[go-nuts] Re: Best practice when creating temporary files

2016-11-21 Thread Ondrej
I already noted that in my very first post, "How do I clean up? As I said, the app does not persist (so I can't defer os.Remove)" I guess I wasn't quite clear about my intentions, so never mind, I'll just handle it somehow. Thanks all for your suggestions. On Monday, 21 November 2016 16:57:56

Re: [go-nuts] Re: Best practice when creating temporary files

2016-11-21 Thread Steven Hartland
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 late

[go-nuts] Re: Best practice when creating temporary files

2016-11-21 Thread Val
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

[go-nuts] Re: Best practice when creating temporary files

2016-11-21 Thread Ondrej
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("", "") >

[go-nuts] Re: Best practice when creating temporary files

2016-11-18 Thread Val
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 so

[go-nuts] Re: Best practice when creating temporary files

2016-11-18 Thread Tamás Gulácsi
2016. november 18., péntek 11:21:23 UTC+1 időpontban Ondrej a következőt írta: > > 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 persi