File tree Expand file tree Collapse file tree 3 files changed +47
-0
lines changed
Expand file tree Collapse file tree 3 files changed +47
-0
lines changed Original file line number Diff line number Diff line change 11.DS_Store
22/release
3+ /test
Original file line number Diff line number Diff line change 1+ package main
2+
3+ import (
4+ "os"
5+ "path/filepath"
6+ "time"
7+ )
8+
9+ func RecursiveTouch (name string ) {
10+ dirs := filepath .Dir (name )
11+ os .MkdirAll (dirs , 0755 )
12+
13+ _ , err := os .Stat (name )
14+ if os .IsNotExist (err ) {
15+ os .Create (name )
16+ } else {
17+ os .Chtimes (name , time .Now (), time .Now ())
18+ }
19+ }
Original file line number Diff line number Diff line change 1+ package main
2+
3+ // TODO: mock the filesystem instead? http://nf.wh3rd.net/10things/#8
4+
5+ import (
6+ "os"
7+ "testing"
8+ )
9+
10+ const (
11+ dir = "test"
12+ )
13+
14+ func init () {
15+ os .RemoveAll (dir )
16+ os .Mkdir (dir , 0755 )
17+ }
18+
19+ func TestRecursiveTouchNew (t * testing.T ) {
20+ name := dir + "/new/file.ext"
21+ RecursiveTouch (name )
22+
23+ _ , err := os .Stat (name )
24+ if err != nil {
25+ t .Errorf ("no such file or directory: '%v'" , name )
26+ }
27+ }
You can’t perform that action at this time.
0 commit comments