Skip to content

Commit 53034d0

Browse files
authored
Merge pull request #438 from sisong/dev-qnx
fix dir-patch when dst-path same as old-path; support QNX OS;
2 parents 505eaa5 + 73af0b2 commit 53034d0

File tree

6 files changed

+91
-28
lines changed

6 files changed

+91
-28
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
full changelog at: https://github.com/sisong/HDiffPatch/commits
44

5+
## [v4.12.1](https://github.com/sisong/HDiffPatch/tree/v4.12.1) - 2026-01-13
6+
### Added
7+
* support dir-diff & dir-patch on QNX OS; by contributor [xiongpan(Oshienai96)](https://github.com/Oshienai96);
8+
### Fixed
9+
* fix a bug when run dir-patch & dst-path same as old-path;
10+
511
## [v4.12.0](https://github.com/sisong/HDiffPatch/tree/v4.12.0) - 2025-09-19
612
### Added
713
* optimize `$hdiffz -m` required memory size when newData similar to oldData;

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# [HDiffPatch]
2-
[![release](https://img.shields.io/badge/release-v4.12.0-blue.svg)](https://github.com/sisong/HDiffPatch/releases)
2+
[![release](https://img.shields.io/badge/release-v4.12.1-blue.svg)](https://github.com/sisong/HDiffPatch/releases)
33
[![license](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/sisong/HDiffPatch/blob/master/LICENSE)
44
[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-blue.svg)](https://github.com/sisong/HDiffPatch/pulls)
55
[![+issue Welcome](https://img.shields.io/github/issues-raw/sisong/HDiffPatch?color=green&label=%2Bissue%20welcome)](https://github.com/sisong/HDiffPatch/issues)

README_cn.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# [HDiffPatch]
2-
[![release](https://img.shields.io/badge/release-v4.12.0-blue.svg)](https://github.com/sisong/HDiffPatch/releases)
2+
[![release](https://img.shields.io/badge/release-v4.12.1-blue.svg)](https://github.com/sisong/HDiffPatch/releases)
33
[![license](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/sisong/HDiffPatch/blob/master/LICENSE)
44
[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-blue.svg)](https://github.com/sisong/HDiffPatch/pulls)
55
[![+issue Welcome](https://img.shields.io/github/issues-raw/sisong/HDiffPatch?color=green&label=%2Bissue%20welcome)](https://github.com/sisong/HDiffPatch/issues)

dirDiffPatch/dir_diff/dir_diff_tools.cpp

Lines changed: 77 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,16 @@
3333
# include <windows.h> //FindFirstFileW ...
3434
#else
3535
# include <dirent.h> //opendir ...
36+
# ifndef _IS_NO_dirent_d_type
37+
# ifdef __QNX__
38+
# define _IS_NO_dirent_d_type 1
39+
# else
40+
# define _IS_NO_dirent_d_type 0
41+
# endif
42+
# endif
43+
# if (_IS_NO_dirent_d_type)
44+
# include <sys/stat.h> //stat
45+
# endif
3646
#endif
3747

3848
#ifdef _WIN32
@@ -101,43 +111,88 @@ void hdiff_dirClose(hdiff_TDirHandle dirHandle){
101111
free(finder);
102112
}
103113
}
114+
// _WIN32
115+
#else
116+
// linux-like
104117

105-
#else // _WIN32
118+
struct _hdiff_TDIRData{
119+
DIR* handle;
120+
#if (_IS_NO_dirent_d_type)
121+
char dirName[hpatch_kPathMaxSize];
122+
#endif
123+
};
106124

107125
hdiff_TDirHandle hdiff_dirOpenForRead(const char* dir_utf8){
108-
hdiff_TDirHandle h=opendir(dir_utf8);
109-
if (!h) return 0; //error
110-
return h;
126+
_hdiff_TDIRData* pdir=(_hdiff_TDIRData*)malloc(sizeof(_hdiff_TDIRData));
127+
if (pdir==0) return 0; //error
128+
pdir->handle=opendir(dir_utf8);
129+
if (!pdir->handle) { hdiff_dirClose(pdir); return 0; }//error
130+
{
131+
#if (_IS_NO_dirent_d_type)
132+
const size_t slen=strlen(dir_utf8);
133+
if (slen>hpatch_kPathMaxSize-1) { hdiff_dirClose(pdir); return 0; }//error
134+
memcpy(pdir->dirName,dir_utf8,slen+1);
135+
#endif
136+
}
137+
return pdir;
111138
}
112139

113140
hpatch_BOOL hdiff_dirNext(hdiff_TDirHandle dirHandle,hpatch_TPathType *out_type,const char** out_subName_utf8){
114141
assert(dirHandle!=0);
115-
DIR* pdir =(DIR*)dirHandle;
116-
struct dirent* pdirent = readdir(pdir);
117-
if (pdirent==0){
118-
*out_subName_utf8=0; //finish
119-
return hpatch_TRUE;
120-
}
121-
122-
if (pdirent->d_type==DT_DIR){
123-
*out_type=kPathType_dir;
124-
*out_subName_utf8=pdirent->d_name;
125-
return hpatch_TRUE;
126-
}else if (pdirent->d_type==DT_REG){
127-
*out_type=kPathType_file;
142+
_hdiff_TDIRData* pdir=(_hdiff_TDIRData*)dirHandle;
143+
while (1){
144+
struct dirent* pdirent = readdir(pdir->handle);
145+
if (pdirent==0){
146+
*out_subName_utf8=0; //finish
147+
return hpatch_TRUE;
148+
}
149+
if ((strcmp(pdirent->d_name,".")==0) || (strcmp(pdirent->d_name,"..")==0))
150+
continue; //next
151+
152+
#if (_IS_NO_dirent_d_type)
153+
{
154+
struct stat s;
155+
char fullName_utf8[hpatch_kPathMaxSize];
156+
int slen=snprintf(fullName_utf8,hpatch_kPathMaxSize,"%s/%s",pdir->dirName,pdirent->d_name);
157+
if ((slen<=0)||(slen>=hpatch_kPathMaxSize)) return hpatch_FALSE;
158+
if (stat(fullName_utf8,&s)!=0) return hpatch_FALSE;
159+
if ((s.st_mode&S_IFMT)==S_IFDIR)
160+
*out_type=kPathType_dir;
161+
else if ((s.st_mode&S_IFMT)==S_IFREG)
162+
*out_type=kPathType_file;
163+
#if (_IS_NEED_BLOCK_DEV)
164+
else if ((s.st_mode&S_IFMT)==S_IFBLK)
165+
*out_type=kPathType_file;
166+
#endif
167+
else
168+
continue; //next
169+
}
170+
#else
171+
if (pdirent->d_type==DT_DIR)
172+
*out_type=kPathType_dir;
173+
else if (pdirent->d_type==DT_REG)
174+
*out_type=kPathType_file;
175+
#if (_IS_NEED_BLOCK_DEV)
176+
else if (pdirent->d_type==DT_BLK)
177+
*out_type=kPathType_file;
178+
#endif
179+
else
180+
continue; //next
181+
#endif
128182
*out_subName_utf8=pdirent->d_name;
129183
return hpatch_TRUE;
130-
}else{
131-
return hdiff_dirNext(dirHandle,out_type,out_subName_utf8);
132184
}
133185
}
134186

135187
void hdiff_dirClose(hdiff_TDirHandle dirHandle){
136-
if (dirHandle)
137-
closedir((DIR*)dirHandle);
188+
_hdiff_TDIRData* pdir=(_hdiff_TDIRData*)dirHandle;
189+
if (pdir){
190+
if (pdir->handle) closedir((DIR*)pdir->handle);
191+
free(pdir);
192+
}
138193
}
139194

140-
#endif // if _WIN32 else
195+
#endif // _WIN32 & linux-like
141196
#endif // _IS_NEED_DIR_DIFF_PATCH
142197

143198

hpatch_dir_listener.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,8 @@ static IHPatchDirListener defaultPatchDirlistener={{0,_makeNewDir,_copySameFile,
109109
return hpatch_removeFile(pathName);
110110
}
111111

112-
typedef const char* (*IDirPathMove_getDstPathBySrcPath)(void* importMove,const char* srcPath);
112+
typedef const char* (*IDirPathMove_getDstPathBySrcPath)(void* importMove,const char* newPath,
113+
char* out_pathBuf,char* out_pathBufEnd);
113114
typedef struct{
114115
void* importMove;
115116
IDirPathMove_getDstPathBySrcPath getDstPathBySrcPath;
@@ -120,6 +121,7 @@ static IHPatchDirListener defaultPatchDirlistener={{0,_makeNewDir,_copySameFile,
120121

121122
static hpatch_BOOL _moveNewToOld(IDirPathMove* dirPathMove) {
122123
char _tmpPath[hpatch_kPathMaxSize];
124+
char _tmpDstPath[hpatch_kPathMaxSize];
123125
hpatch_BOOL result=hpatch_TRUE;
124126
IDirPathList* dstPathList=&dirPathMove->dstPathList;
125127
IDirPathList* srcPathList=&dirPathMove->srcPathList;
@@ -145,7 +147,7 @@ static IHPatchDirListener defaultPatchDirlistener={{0,_makeNewDir,_copySameFile,
145147
const char* srcPath=srcPathList->getPathNameByIndex(srcPathList->import,srcPathIndex,_tmpPath,_tmpPath+sizeof(_tmpPath));
146148
if (srcPath==0) { result=hpatch_FALSE; continue; }
147149
if (hpatch_getIsDirName(srcPath)){
148-
const char* dstDir=dirPathMove->getDstPathBySrcPath(dirPathMove->importMove,srcPath);
150+
const char* dstDir=dirPathMove->getDstPathBySrcPath(dirPathMove->importMove,srcPath,_tmpDstPath,_tmpDstPath+sizeof(_tmpDstPath));
149151
if (dstDir==0) { result=hpatch_FALSE; continue; }
150152
if (!hpatch_makeNewDir(dstDir)) { _update_ferr(dirPathMove->fileError); result=hpatch_FALSE; continue; }
151153
}
@@ -157,7 +159,7 @@ static IHPatchDirListener defaultPatchDirlistener={{0,_makeNewDir,_copySameFile,
157159
if (hpatch_getIsDirName(srcPath)){
158160
hpatch_removeDir(srcPath);
159161
}else{
160-
const char* dstPath=dirPathMove->getDstPathBySrcPath(dirPathMove->importMove,srcPath);
162+
const char* dstPath=dirPathMove->getDstPathBySrcPath(dirPathMove->importMove,srcPath,_tmpDstPath,_tmpDstPath+sizeof(_tmpDstPath));
161163
if (dstPath==0) { result=hpatch_FALSE; continue; }
162164
hpatch_removeFile(dstPath);//overwrite
163165
if (!hpatch_moveFile(srcPath,dstPath)){//move src to dst

libHDiffPatch/HPatch/patch_types.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ extern "C" {
3838

3939
#define HDIFFPATCH_VERSION_MAJOR 4
4040
#define HDIFFPATCH_VERSION_MINOR 12
41-
#define HDIFFPATCH_VERSION_RELEASE 0
41+
#define HDIFFPATCH_VERSION_RELEASE 1
4242

4343
#define _HDIFFPATCH_VERSION HDIFFPATCH_VERSION_MAJOR.HDIFFPATCH_VERSION_MINOR.HDIFFPATCH_VERSION_RELEASE
4444
#define _HDIFFPATCH_QUOTE(str) #str

0 commit comments

Comments
 (0)