From 50ef5053ff0fd42bcf572fa596b1dd63f83c8f75 Mon Sep 17 00:00:00 2001 From: moqsien Date: Wed, 13 Jul 2022 23:26:54 +0800 Subject: [PATCH] push asyncly --- package.json | 2 +- src/tools.ts | 6 ++++-- src/utils.ts | 24 ++++++++++++++++-------- 3 files changed, 21 insertions(+), 11 deletions(-) diff --git a/package.json b/package.json index b75d47c..3d8a0f8 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "displayName": "easynotes", "publisher": "moqsien", "description": "store notes easily", - "version": "0.0.1", + "version": "0.0.2", "repository": { "type": "git", "url": "https://github.com/moqsien/easynotes.git" diff --git a/src/tools.ts b/src/tools.ts index f72459a..a13fa7f 100644 --- a/src/tools.ts +++ b/src/tools.ts @@ -36,10 +36,12 @@ export class SyncFiles{ } - public async createRootDir() :Promise { + public async createRootDir() :Promise { if (!(await this.client.exists(this.remoteRoot))) { await this.client.createDirectory(this.remoteRoot); - } + return true; + }; + return false; }; public async isVersionExists(): Promise { diff --git a/src/utils.ts b/src/utils.ts index 552fc0b..4b2325f 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -3,6 +3,7 @@ import * as vscode from 'vscode'; import { SyncFiles } from './tools'; import fs = require("fs"); import path = require("path"); +import { resolve } from 'path'; export class Config implements ToolConfig { public webdavUrl: string; @@ -65,20 +66,27 @@ export function loadConfigFile(workspaceFolders: any) :Config { }); }; -function pushNoteFiles(conf: ToolConfig) { +function sleep(ms: number) { + return new Promise(resolve=>setTimeout(resolve, ms)); +}; + +async function pushNoteFiles(conf: ToolConfig) { let cnf = new SyncFiles(conf); - cnf.createRootDir(); - cnf.isVersionExists(); + let flag: boolean = await cnf.createRootDir(); + if (flag) { + await sleep(2000); + }; + await cnf.isVersionExists(); cnf.createVersion(true); - cnf.pushWalkDirs(conf.localRoot); - cnf.deleteRemoteFiles(conf.remoteRoot); + await cnf.pushWalkDirs(conf.localRoot); + await cnf.deleteRemoteFiles(conf.remoteRoot); vscode.window.showInformationMessage("push file completed!"); }; -function pullhNoteFiles(conf: ToolConfig) { +async function pullhNoteFiles(conf: ToolConfig) { let cnf = new SyncFiles(conf); - cnf.pullWalkDirs(conf.remoteRoot); - cnf.deleteLocalFiles(conf.localRoot); + await cnf.pullWalkDirs(conf.remoteRoot); + await cnf.deleteLocalFiles(conf.localRoot); vscode.window.showInformationMessage("pull file completed!"); };