mirror of
https://github.com/siyuan-note/siyuan.git
synced 2026-02-24 16:04:06 +01:00
♻️ Refactor Go to err != nil, err == nil (#12385)
This commit is contained in:
parent
473a159ef2
commit
b100721fee
147 changed files with 1661 additions and 1659 deletions
|
|
@ -93,7 +93,7 @@ func RandomSleep(minMills, maxMills int) {
|
|||
func GetDeviceID() string {
|
||||
if ContainerStd == Container {
|
||||
machineID, err := machineid.ID()
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
return gulu.Rand.String(12)
|
||||
}
|
||||
return machineID
|
||||
|
|
@ -103,17 +103,17 @@ func GetDeviceID() string {
|
|||
|
||||
func GetDeviceName() string {
|
||||
ret, err := os.Hostname()
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
return "unknown"
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
func SetNetworkProxy(proxyURL string) {
|
||||
if err := os.Setenv("HTTPS_PROXY", proxyURL); nil != err {
|
||||
if err := os.Setenv("HTTPS_PROXY", proxyURL); err != nil {
|
||||
logging.LogErrorf("set env [HTTPS_PROXY] failed: %s", err)
|
||||
}
|
||||
if err := os.Setenv("HTTP_PROXY", proxyURL); nil != err {
|
||||
if err := os.Setenv("HTTP_PROXY", proxyURL); err != nil {
|
||||
logging.LogErrorf("set env [HTTP_PROXY] failed: %s", err)
|
||||
}
|
||||
|
||||
|
|
@ -186,12 +186,12 @@ func checkFileSysStatus() {
|
|||
}
|
||||
|
||||
dir := filepath.Join(DataDir, fileSysStatusCheckFile)
|
||||
if err := os.RemoveAll(dir); nil != err {
|
||||
if err := os.RemoveAll(dir); err != nil {
|
||||
ReportFileSysFatalError(err)
|
||||
return
|
||||
}
|
||||
|
||||
if err := os.MkdirAll(dir, 0755); nil != err {
|
||||
if err := os.MkdirAll(dir, 0755); err != nil {
|
||||
ReportFileSysFatalError(err)
|
||||
return
|
||||
}
|
||||
|
|
@ -200,12 +200,12 @@ func checkFileSysStatus() {
|
|||
tmp := filepath.Join(dir, "check_consistency")
|
||||
data := make([]byte, 1024*4)
|
||||
_, err := rand.Read(data)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
ReportFileSysFatalError(err)
|
||||
return
|
||||
}
|
||||
|
||||
if err = os.WriteFile(tmp, data, 0644); nil != err {
|
||||
if err = os.WriteFile(tmp, data, 0644); err != nil {
|
||||
ReportFileSysFatalError(err)
|
||||
return
|
||||
}
|
||||
|
|
@ -214,7 +214,7 @@ func checkFileSysStatus() {
|
|||
|
||||
for j := 0; j < 32; j++ {
|
||||
renamed := tmp + "_renamed"
|
||||
if err = os.Rename(tmp, renamed); nil != err {
|
||||
if err = os.Rename(tmp, renamed); err != nil {
|
||||
ReportFileSysFatalError(err)
|
||||
break
|
||||
}
|
||||
|
|
@ -222,23 +222,23 @@ func checkFileSysStatus() {
|
|||
RandomSleep(500, 1000)
|
||||
|
||||
f, err := os.Open(renamed)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
ReportFileSysFatalError(err)
|
||||
return
|
||||
}
|
||||
|
||||
if err = f.Close(); nil != err {
|
||||
if err = f.Close(); err != nil {
|
||||
ReportFileSysFatalError(err)
|
||||
return
|
||||
}
|
||||
|
||||
if err = os.Rename(renamed, tmp); nil != err {
|
||||
if err = os.Rename(renamed, tmp); err != nil {
|
||||
ReportFileSysFatalError(err)
|
||||
return
|
||||
}
|
||||
|
||||
entries, err := os.ReadDir(dir)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
ReportFileSysFatalError(err)
|
||||
return
|
||||
}
|
||||
|
|
@ -264,7 +264,7 @@ func checkFileSysStatus() {
|
|||
}
|
||||
}
|
||||
|
||||
if err = os.RemoveAll(tmp); nil != err {
|
||||
if err = os.RemoveAll(tmp); err != nil {
|
||||
ReportFileSysFatalError(err)
|
||||
return
|
||||
}
|
||||
|
|
@ -343,33 +343,33 @@ func existAvailabilityStatus(workspaceAbsPath string) bool {
|
|||
|
||||
runtime.LockOSThread()
|
||||
defer runtime.LockOSThread()
|
||||
if err := ole.CoInitializeEx(0, ole.COINIT_MULTITHREADED); nil != err {
|
||||
if err := ole.CoInitializeEx(0, ole.COINIT_MULTITHREADED); err != nil {
|
||||
logging.LogWarnf("initialize ole failed: %s", err)
|
||||
return false
|
||||
}
|
||||
defer ole.CoUninitialize()
|
||||
dir, file := filepath.Split(checkAbsPath)
|
||||
unknown, err := oleutil.CreateObject("Shell.Application")
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
logging.LogWarnf("create shell application failed: %s", err)
|
||||
return false
|
||||
}
|
||||
shell, err := unknown.QueryInterface(ole.IID_IDispatch)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
logging.LogWarnf("query shell interface failed: %s", err)
|
||||
return false
|
||||
}
|
||||
defer shell.Release()
|
||||
|
||||
result, err := oleutil.CallMethod(shell, "NameSpace", dir)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
logging.LogWarnf("call shell [NameSpace] failed: %s", err)
|
||||
return false
|
||||
}
|
||||
folderObj := result.ToIDispatch()
|
||||
|
||||
result, err = oleutil.CallMethod(folderObj, "ParseName", file)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
logging.LogWarnf("call shell [ParseName] failed: %s", err)
|
||||
return false
|
||||
}
|
||||
|
|
@ -380,7 +380,7 @@ func existAvailabilityStatus(workspaceAbsPath string) bool {
|
|||
}
|
||||
|
||||
result, err = oleutil.CallMethod(folderObj, "GetDetailsOf", fileObj, 303)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
logging.LogWarnf("call shell [GetDetailsOf] failed: %s", err)
|
||||
return false
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue