diff options
| author | Grant Ammons <gammons@gmail.com> | 2016-05-08 20:01:31 -0400 |
|---|---|---|
| committer | Grant Ammons <gammons@gmail.com> | 2016-05-08 20:01:31 -0400 |
| commit | d815e1ad59ce0cfd21895144109bff2ed4072b13 (patch) | |
| tree | dbf7e670d0d8c1b4f1fe4731aab91787e864b571 | |
| parent | a886124d40f79f311230d2f03f161fd361e43040 (diff) | |
Ensure we don't destroy an existing .todos.json
| -rw-r--r-- | todolist/file_store.go | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/todolist/file_store.go b/todolist/file_store.go index f8e3a71..faf235f 100644 --- a/todolist/file_store.go +++ b/todolist/file_store.go @@ -108,6 +108,11 @@ func (f *FileStore) Load() { } func (f *FileStore) Initialize() { + _, err := ioutil.ReadFile(f.FileLocation) + if err == nil { + fmt.Println("It looks like a .todos.json file already exists! Doing nothing.") + os.Exit(0) + } if err := ioutil.WriteFile(f.FileLocation, []byte("[]"), 0644); err != nil { fmt.Println("Error writing json file", err) } |
