Mercurial > go > multipass
comparison file/file.go @ 15:9b4ec6b5c23e
Add tests for multipass files.
author | Paul Fisher <paul@pfish.zone> |
---|---|
date | Thu, 29 Oct 2015 23:56:53 -0400 |
parents | da6c493cf08a |
children | 00d30c67b56d |
comparison
equal
deleted
inserted
replaced
14:4368a377ff64 | 15:9b4ec6b5c23e |
---|---|
21 // the Banner acts as a version indicator | 21 // the Banner acts as a version indicator |
22 Banner = "# Multipass v0.1 password file" | 22 Banner = "# Multipass v0.1 password file" |
23 ) | 23 ) |
24 | 24 |
25 var ( | 25 var ( |
26 // Raised when | 26 // Raised when there's an error in the file format. |
27 ErrorBadFile = errors.New("multipass/file: Invalid file format") | 27 ErrorBadFile = errors.New("multipass/file: Invalid file format") |
28 | |
29 // we spin waiting for the file to become available, doubling our wait time | |
30 // every time it's unavailable. If the wait time is longer than this, | |
31 // give up. Variable so it can be set in tests. | |
32 maxDelay = time.Minute | |
28 ) | 33 ) |
29 | 34 |
30 type ShadowFile struct { | 35 type ShadowFile struct { |
31 name string | 36 name string |
32 } | 37 } |
174 perr := err.(*os.PathError) | 179 perr := err.(*os.PathError) |
175 errno, ok := perr.Err.(syscall.Errno) | 180 errno, ok := perr.Err.(syscall.Errno) |
176 if !ok { | 181 if !ok { |
177 return nil, err | 182 return nil, err |
178 } | 183 } |
179 if errno != syscall.EEXIST || delay > time.Minute { | 184 if errno != syscall.EEXIST || delay > maxDelay { |
180 return nil, err | 185 return nil, err |
181 } | 186 } |
182 time.Sleep(delay) | 187 time.Sleep(delay) |
183 delay *= 2 | 188 delay *= 2 |
184 } | 189 } |