From 572dd8ec3953ea1e878f689b2759c8fc9642ff94 Mon Sep 17 00:00:00 2001 From: wangmm0220 Date: Fri, 3 Nov 2023 17:14:04 +0800 Subject: [PATCH] fix:add windows support --- source/common/src/tglobal.c | 2 +- source/util/src/rsync.c | 30 ++++++++++++++++++++++++++++-- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/source/common/src/tglobal.c b/source/common/src/tglobal.c index 639e300179..51c141c754 100644 --- a/source/common/src/tglobal.c +++ b/source/common/src/tglobal.c @@ -136,7 +136,7 @@ char tsSmlAutoChildTableNameDelimiter[TSDB_TABLE_NAME_LEN] = ""; // checkpoint backup char tsSnodeIp[TSDB_FQDN_LEN] = {0}; #ifdef WINDOWS -char tsCheckpointBackupDir[PATH_MAX] = "/c/TDengine/data/backup/checkpoint/"; +char tsCheckpointBackupDir[PATH_MAX] = "C:\TDengine\data\backup\checkpoint\"; #else char tsCheckpointBackupDir[PATH_MAX] = "/var/lib/taos/backup/checkpoint/"; #endif diff --git a/source/util/src/rsync.c b/source/util/src/rsync.c index e3908e53ba..6316be7f79 100644 --- a/source/util/src/rsync.c +++ b/source/util/src/rsync.c @@ -38,6 +38,21 @@ static void removeEmptyDir(){ taosCloseDir(&pDir); } +#ifdef WINDOWS +// C:\TDengine\data\backup\checkpoint\ -> /c/TDengine/data/backup/checkpoint/ +static void changeDirFromWindowsToLinux(char* from, char* to){ + to[0] = '/'; + to[1] = from[0]; + for(int i = 2; i < strlen(from); i++) { + if (from[i] == '\\') { + to[i] = '/'; + } else { + to[i] = from[i]; + } + } +} +#endif + static int generateConfigFile(char* confDir){ TdFilePtr pFile = taosOpenFile(confDir, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC); if (pFile == NULL) { @@ -45,6 +60,11 @@ static int generateConfigFile(char* confDir){ return -1; } +#ifdef WINDOWS + char path[PATH_MAX] = {0}; + changeDirFromWindowsToLinux(tsCheckpointBackupDir, path); +#endif + char confContent[PATH_MAX*4] = {0}; snprintf(confContent, PATH_MAX*4, #ifndef WINDOWS @@ -60,7 +80,13 @@ static int generateConfigFile(char* confDir){ "read only = false\n" "list = false\n" "[checkpoint]\n" - "path = %s", tsCheckpointBackupDir, tsCheckpointBackupDir, tsCheckpointBackupDir); + "path = %s", tsCheckpointBackupDir, tsCheckpointBackupDir, +#ifdef WINDOWS + path +#else + tsCheckpointBackupDir +#endif + ); uDebug("[rsync] conf:%s", confContent); if (taosWriteFile(pFile, confContent, strlen(confContent)) <= 0){ uError("[rsync] write conf file error,"ERRNO_ERR_FORMAT, ERRNO_ERR_DATA); @@ -88,7 +114,7 @@ static int execCommand(char* command){ void stopRsync(){ int code = #ifdef WINDOWS - system("taskkill /f /mi rsync.exe"); + system("taskkill /f /im rsync.exe"); #else system("pkill rsync"); #endif