Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2)

Side by Side Diff: vpython/filesystem/testfs/tempdir.go

Issue 2703793003: vpython: Add filesystem operation / test packages. (Closed)
Patch Set: Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2017 The LUCI Authors. All rights reserved.
2 // Use of this source code is governed under the Apache License, Version 2.0
3 // that can be found in the LICENSE file.
4
5 package testfs
6
7 import (
8 "io/ioutil"
9
10 "github.com/luci/luci-go/vpython/filesystem"
11 )
12
13 // WithTempDir creates a temporary directory and passes it to fn. After fn
14 // exits, the directory is cleaned up.
15 func WithTempDir(prefix string, fn func(string) error) error {
16 tdir, err := ioutil.TempDir("", prefix)
17 if err != nil {
18 return err
19 }
20 defer func() {
21 _ = filesystem.RemoveAll(tdir)
iannucci 2017/02/21 08:25:09 worth logging?
dnj 2017/02/21 18:07:49 Done.
22 }()
23 return fn(tdir)
24 }
25
26 // MustWithTempDir calls WithTempDir and panics if any failures occur.
27 func MustWithTempDir(prefix string, fn func(string)) func() {
28 return func() {
29 err := WithTempDir(prefix, func(tdir string) error {
30 fn(tdir)
31 return nil
32 })
33 if err != nil {
34 panic(err)
35 }
36 }
37 }
OLDNEW
« vpython/filesystem/testfs/build.go ('K') | « vpython/filesystem/testfs/build.go ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698