Merge pull request #1094 from harshavardhana/add-create

Create an empty urls.json if doesn't exist while reading.
This commit is contained in:
Harshavardhana
2015-09-12 18:43:02 -07:00
2 changed files with 9 additions and 9 deletions
+8 -4
View File
@@ -133,11 +133,15 @@ func mainShare(ctx *cli.Context) {
checkShareSyntax(ctx)
if !isSharedURLsDataDirExists() {
shareDir, _ := getSharedURLsDataDir()
shareDir, err := getSharedURLsDataDir()
fatalIf(err.Trace(), "Unable to get shared URL data directory")
fatalIf(createSharedURLsDataDir().Trace(), "Unable to create shared URL data directory ‘"+shareDir+"’.")
}
if !isSharedURLsDataFileExists() {
shareFile, _ := getSharedURLsDataFile()
shareFile, err := getSharedURLsDataFile()
fatalIf(err.Trace(), "Unable to get shared URL data file")
fatalIf(createSharedURLsDataFile().Trace(), "Unable to create shared URL data file ‘"+shareFile+"’.")
}
@@ -196,8 +200,8 @@ func doShareList() *probe.Error {
continue
}
shareListBytes, err := json.Marshal(struct {
ExpiresIn time.Duration
URL string
ExpiresIn time.Duration `json:"expiresIn"`
URL string `json:"url"`
}{
ExpiresIn: time.Duration(expiresIn.Seconds()),
URL: url,
+1 -5
View File
@@ -109,11 +109,7 @@ func loadSharedURLsV1() (*sharedURLs, *probe.Error) {
return nil, err.Trace()
}
if _, err := os.Stat(sharedURLsDataFile); err != nil {
// If not found, initialize an empty json file.
if os.IsNotExist(err) {
} else {
return nil, probe.NewError(err)
}
return nil, probe.NewError(err)
}
qs, err := quick.New(newSharedURLs())