mirror of
https://github.com/zyedidia/micro.git
synced 2025-06-18 23:05:40 -04:00
Only write settings if no error when reading
This commit also switches from yosuke-furukawa/json5 to flynn/json5 because yosuke-furukawa/json5 does not provide a license. Ref zyedidia/json5#1 Closes #775
This commit is contained in:
parent
5c785ab1ac
commit
202cfb574c
6
.gitmodules
vendored
6
.gitmodules
vendored
@ -31,9 +31,6 @@
|
|||||||
[submodule "cmd/micro/vendor/github.com/zyedidia/glob"]
|
[submodule "cmd/micro/vendor/github.com/zyedidia/glob"]
|
||||||
path = cmd/micro/vendor/github.com/zyedidia/glob
|
path = cmd/micro/vendor/github.com/zyedidia/glob
|
||||||
url = https://github.com/zyedidia/glob
|
url = https://github.com/zyedidia/glob
|
||||||
[submodule "cmd/micro/vendor/github.com/zyedidia/json5"]
|
|
||||||
path = cmd/micro/vendor/github.com/zyedidia/json5
|
|
||||||
url = https://github.com/zyedidia/json5
|
|
||||||
[submodule "cmd/micro/vendor/github.com/zyedidia/tcell"]
|
[submodule "cmd/micro/vendor/github.com/zyedidia/tcell"]
|
||||||
path = cmd/micro/vendor/github.com/zyedidia/tcell
|
path = cmd/micro/vendor/github.com/zyedidia/tcell
|
||||||
url = https://github.com/zyedidia/tcell
|
url = https://github.com/zyedidia/tcell
|
||||||
@ -55,3 +52,6 @@
|
|||||||
[submodule "cmd/micro/vendor/github.com/zyedidia/poller"]
|
[submodule "cmd/micro/vendor/github.com/zyedidia/poller"]
|
||||||
path = cmd/micro/vendor/github.com/zyedidia/poller
|
path = cmd/micro/vendor/github.com/zyedidia/poller
|
||||||
url = https://github.com/zyedidia/poller
|
url = https://github.com/zyedidia/poller
|
||||||
|
[submodule "cmd/micro/vendor/github.com/flynn/json5"]
|
||||||
|
path = cmd/micro/vendor/github.com/flynn/json5
|
||||||
|
url = https://github.com/flynn/json5
|
||||||
|
@ -1106,3 +1106,61 @@ Exhibit B - "Incompatible With Secondary Licenses" Notice
|
|||||||
|
|
||||||
This Source Code Form is "Incompatible With Secondary Licenses", as
|
This Source Code Form is "Incompatible With Secondary Licenses", as
|
||||||
defined by the Mozilla Public License, v. 2.0.
|
defined by the Mozilla Public License, v. 2.0.
|
||||||
|
|
||||||
|
github.com/flynn/json5/LICENSE
|
||||||
|
================
|
||||||
|
|
||||||
|
Decoder code based on package encoding/json from the Go language.
|
||||||
|
|
||||||
|
Copyright (c) 2012 The Go Authors. All rights reserved.
|
||||||
|
|
||||||
|
Redistribution and use in source and binary forms, with or without
|
||||||
|
modification, are permitted provided that the following conditions are
|
||||||
|
met:
|
||||||
|
|
||||||
|
* Redistributions of source code must retain the above copyright
|
||||||
|
notice, this list of conditions and the following disclaimer.
|
||||||
|
* Redistributions in binary form must reproduce the above
|
||||||
|
copyright notice, this list of conditions and the following disclaimer
|
||||||
|
in the documentation and/or other materials provided with the
|
||||||
|
distribution.
|
||||||
|
* Neither the name of Google Inc. nor the names of its
|
||||||
|
contributors may be used to endorse or promote products derived from
|
||||||
|
this software without specific prior written permission.
|
||||||
|
|
||||||
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||||
|
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||||
|
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||||
|
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||||
|
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||||
|
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||||
|
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
|
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Test data based on the parse cases from https://github.com/json5/json5
|
||||||
|
|
||||||
|
Copyright (c) 2012-2016 Aseem Kishore, and others.
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
a copy of this software and associated documentation files (the
|
||||||
|
"Software"), to deal in the Software without restriction, including
|
||||||
|
without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be
|
||||||
|
included in all copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||||
|
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||||
|
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||||
|
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||||
|
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
@ -5,7 +5,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/zyedidia/json5/encoding/json5"
|
"github.com/flynn/json5"
|
||||||
"github.com/zyedidia/tcell"
|
"github.com/zyedidia/tcell"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -14,8 +14,8 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/blang/semver"
|
"github.com/blang/semver"
|
||||||
|
"github.com/flynn/json5"
|
||||||
"github.com/yuin/gopher-lua"
|
"github.com/yuin/gopher-lua"
|
||||||
"github.com/zyedidia/json5/encoding/json5"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -1,10 +1,11 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/blang/semver"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/zyedidia/json5/encoding/json5"
|
"github.com/blang/semver"
|
||||||
|
|
||||||
|
"github.com/flynn/json5"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestDependencyResolving(t *testing.T) {
|
func TestDependencyResolving(t *testing.T) {
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
@ -8,8 +9,8 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/flynn/json5"
|
||||||
"github.com/zyedidia/glob"
|
"github.com/zyedidia/glob"
|
||||||
"github.com/zyedidia/json5/encoding/json5"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type optionValidator func(string, interface{}) error
|
type optionValidator func(string, interface{}) error
|
||||||
@ -17,6 +18,8 @@ type optionValidator func(string, interface{}) error
|
|||||||
// The options that the user can set
|
// The options that the user can set
|
||||||
var globalSettings map[string]interface{}
|
var globalSettings map[string]interface{}
|
||||||
|
|
||||||
|
var invalidSettings bool
|
||||||
|
|
||||||
// Options with validators
|
// Options with validators
|
||||||
var optionValidators = map[string]optionValidator{
|
var optionValidators = map[string]optionValidator{
|
||||||
"tabsize": validatePositiveValue,
|
"tabsize": validatePositiveValue,
|
||||||
@ -28,6 +31,7 @@ var optionValidators = map[string]optionValidator{
|
|||||||
|
|
||||||
// InitGlobalSettings initializes the options map and sets all options to their default values
|
// InitGlobalSettings initializes the options map and sets all options to their default values
|
||||||
func InitGlobalSettings() {
|
func InitGlobalSettings() {
|
||||||
|
invalidSettings = false
|
||||||
defaults := DefaultGlobalSettings()
|
defaults := DefaultGlobalSettings()
|
||||||
var parsed map[string]interface{}
|
var parsed map[string]interface{}
|
||||||
|
|
||||||
@ -38,12 +42,14 @@ func InitGlobalSettings() {
|
|||||||
if !strings.HasPrefix(string(input), "null") {
|
if !strings.HasPrefix(string(input), "null") {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
TermMessage("Error reading settings.json file: " + err.Error())
|
TermMessage("Error reading settings.json file: " + err.Error())
|
||||||
|
invalidSettings = true
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
err = json5.Unmarshal(input, &parsed)
|
err = json5.Unmarshal(input, &parsed)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
TermMessage("Error reading settings.json:", err.Error())
|
TermMessage("Error reading settings.json:", err.Error())
|
||||||
|
invalidSettings = true
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
writeSettings = true
|
writeSettings = true
|
||||||
@ -71,6 +77,7 @@ func InitGlobalSettings() {
|
|||||||
// InitLocalSettings scans the json in settings.json and sets the options locally based
|
// InitLocalSettings scans the json in settings.json and sets the options locally based
|
||||||
// on whether the buffer matches the glob
|
// on whether the buffer matches the glob
|
||||||
func InitLocalSettings(buf *Buffer) {
|
func InitLocalSettings(buf *Buffer) {
|
||||||
|
invalidSettings = false
|
||||||
var parsed map[string]interface{}
|
var parsed map[string]interface{}
|
||||||
|
|
||||||
filename := configDir + "/settings.json"
|
filename := configDir + "/settings.json"
|
||||||
@ -78,12 +85,14 @@ func InitLocalSettings(buf *Buffer) {
|
|||||||
input, err := ioutil.ReadFile(filename)
|
input, err := ioutil.ReadFile(filename)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
TermMessage("Error reading settings.json file: " + err.Error())
|
TermMessage("Error reading settings.json file: " + err.Error())
|
||||||
|
invalidSettings = true
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
err = json5.Unmarshal(input, &parsed)
|
err = json5.Unmarshal(input, &parsed)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
TermMessage("Error reading settings.json:", err.Error())
|
TermMessage("Error reading settings.json:", err.Error())
|
||||||
|
invalidSettings = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -106,6 +115,11 @@ func InitLocalSettings(buf *Buffer) {
|
|||||||
|
|
||||||
// WriteSettings writes the settings to the specified filename as JSON
|
// WriteSettings writes the settings to the specified filename as JSON
|
||||||
func WriteSettings(filename string) error {
|
func WriteSettings(filename string) error {
|
||||||
|
if invalidSettings {
|
||||||
|
// Do not write the settings if there was an error when reading them
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
var err error
|
var err error
|
||||||
if _, e := os.Stat(configDir); e == nil {
|
if _, e := os.Stat(configDir); e == nil {
|
||||||
parsed := make(map[string]interface{})
|
parsed := make(map[string]interface{})
|
||||||
@ -124,6 +138,7 @@ func WriteSettings(filename string) error {
|
|||||||
err = json5.Unmarshal(input, &parsed)
|
err = json5.Unmarshal(input, &parsed)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
TermMessage("Error reading settings.json:", err.Error())
|
TermMessage("Error reading settings.json:", err.Error())
|
||||||
|
invalidSettings = true
|
||||||
}
|
}
|
||||||
|
|
||||||
for k, v := range parsed {
|
for k, v := range parsed {
|
||||||
@ -136,7 +151,7 @@ func WriteSettings(filename string) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
txt, _ := json5.MarshalIndent(parsed, "", " ")
|
txt, _ := json.MarshalIndent(parsed, "", " ")
|
||||||
err = ioutil.WriteFile(filename, append(txt, '\n'), 0644)
|
err = ioutil.WriteFile(filename, append(txt, '\n'), 0644)
|
||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
|
1
cmd/micro/vendor/github.com/flynn/json5
generated
vendored
Submodule
1
cmd/micro/vendor/github.com/flynn/json5
generated
vendored
Submodule
@ -0,0 +1 @@
|
|||||||
|
Subproject commit 7620272ed63390e979cf5882d2fa0506fe2a8db5
|
1
cmd/micro/vendor/github.com/zyedidia/json5
generated
vendored
1
cmd/micro/vendor/github.com/zyedidia/json5
generated
vendored
@ -1 +0,0 @@
|
|||||||
Subproject commit 2518f8beebde6814f2d30d566260480d2ded2f76
|
|
Loading…
Reference in New Issue
Block a user