mirror of https://github.com/Wox-launcher/Wox
refactor(resource): improve directory cleanup in `Extract` function
* Added checks to remove existing directories before extracting files for hosts, ui, others, and script_plugin_templates. * Enhanced logging in `StartUIApp` to include the app path in the error message when the UI app does not exist.
This commit is contained in:
parent
fe23eed7b6
commit
9f9cf84ea8
|
@ -35,26 +35,60 @@ var embedThemes = []string{}
|
|||
|
||||
func Extract(ctx context.Context) error {
|
||||
start := util.GetSystemTimestamp()
|
||||
extractHostErr := extractFiles(ctx, HostFS, util.GetLocation().GetHostDirectory(), "hosts", false)
|
||||
|
||||
// hosts
|
||||
hostDirectory := util.GetLocation().GetHostDirectory()
|
||||
if util.IsDirExists(hostDirectory) {
|
||||
rmErr := os.RemoveAll(hostDirectory)
|
||||
if rmErr != nil {
|
||||
return rmErr
|
||||
}
|
||||
}
|
||||
extractHostErr := extractFiles(ctx, HostFS, hostDirectory, "hosts", false)
|
||||
if extractHostErr != nil {
|
||||
return extractHostErr
|
||||
}
|
||||
|
||||
flutterErr := extractFiles(ctx, UIFS, util.GetLocation().GetUIDirectory(), "ui/flutter", true)
|
||||
// ui
|
||||
uiDiretory := util.GetLocation().GetUIDirectory()
|
||||
if util.IsDirExists(uiDiretory) {
|
||||
rmErr := os.RemoveAll(uiDiretory)
|
||||
if rmErr != nil {
|
||||
return rmErr
|
||||
}
|
||||
}
|
||||
flutterErr := extractFiles(ctx, UIFS, uiDiretory, "ui/flutter", true)
|
||||
if flutterErr != nil {
|
||||
return flutterErr
|
||||
}
|
||||
|
||||
othersErr := extractFiles(ctx, OthersFS, util.GetLocation().GetOthersDirectory(), "others", false)
|
||||
// others
|
||||
othersDirectory := util.GetLocation().GetOthersDirectory()
|
||||
if util.IsDirExists(othersDirectory) {
|
||||
rmErr := os.RemoveAll(othersDirectory)
|
||||
if rmErr != nil {
|
||||
return rmErr
|
||||
}
|
||||
}
|
||||
othersErr := extractFiles(ctx, OthersFS, othersDirectory, "others", false)
|
||||
if othersErr != nil {
|
||||
return othersErr
|
||||
}
|
||||
|
||||
scriptPluginTemplatesErr := extractFiles(ctx, ScriptPluginTemplatesFS, util.GetLocation().GetScriptPluginTemplatesDirectory(), "script_plugin_templates", false)
|
||||
// script_plugin_templates
|
||||
scriptPluginTemplatesDirectory := util.GetLocation().GetScriptPluginTemplatesDirectory()
|
||||
if util.IsDirExists(scriptPluginTemplatesDirectory) {
|
||||
rmErr := os.RemoveAll(scriptPluginTemplatesDirectory)
|
||||
if rmErr != nil {
|
||||
return rmErr
|
||||
}
|
||||
}
|
||||
scriptPluginTemplatesErr := extractFiles(ctx, ScriptPluginTemplatesFS, scriptPluginTemplatesDirectory, "script_plugin_templates", false)
|
||||
if scriptPluginTemplatesErr != nil {
|
||||
return scriptPluginTemplatesErr
|
||||
}
|
||||
|
||||
// themes
|
||||
themeErr := parseThemes(ctx)
|
||||
if themeErr != nil {
|
||||
return themeErr
|
||||
|
|
|
@ -295,7 +295,7 @@ func (m *Manager) UpdateServerPort(port int) {
|
|||
func (m *Manager) StartUIApp(ctx context.Context) error {
|
||||
var appPath = util.GetLocation().GetUIAppPath()
|
||||
if fileInfo, statErr := os.Stat(appPath); os.IsNotExist(statErr) {
|
||||
logger.Info(ctx, "UI app not exist")
|
||||
logger.Info(ctx, "UI app not exist: "+appPath)
|
||||
return errors.New("UI app not exist")
|
||||
} else {
|
||||
if !util.IsFileExecAny(fileInfo.Mode()) {
|
||||
|
|
Loading…
Reference in New Issue