Skip to content

Commit 9a0aec0

Browse files
committed
Few Changes
* inline `RemoveFd` * Rename `RemoveFd2` to `RemoveFd` * Merge conditionals in `RenameAt2 * Remove debug info from releases
1 parent 6884a16 commit 9a0aec0

3 files changed

Lines changed: 30 additions & 30 deletions

File tree

.github/workflows/build.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@ jobs:
2626
uses: egor-tensin/vs-shell@v2
2727

2828
- name: Compile Library
29-
run: cl /O2 /std:c++17 /LD /Zi FileSystem.cc
29+
run: cl /O2 /std:c++17 /LD FileSystem.cc
3030

3131
- name: Test Node.js Module
3232
run: npm i
3333

3434
- name: Zip Library
35-
run: powershell Compress-Archive -Path FileSystem.dll,FileSystem.lib,FileSystem.pdb,FileSystem.h,fsdef.h -DestinationPath FileSystem-windows.zip
35+
run: powershell Compress-Archive -Path FileSystem.dll,FileSystem.lib,FileSystem.h,fsdef.h -DestinationPath FileSystem-windows.zip
3636

3737
- name: Upload Library
3838
uses: actions/upload-artifact@v4
@@ -52,7 +52,7 @@ jobs:
5252
uses: actions/checkout@v4
5353

5454
- name: Compile Library
55-
run: g++ -O2 -g -fPIC -shared -o FileSystem.so FileSystem.cc
55+
run: g++ -O2 -fPIC -shared -o FileSystem.so FileSystem.cc
5656

5757
- name: Test Node.js Module
5858
run: npm i

FileSystem.cc

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -797,7 +797,7 @@ namespace {
797797
++fs->fdCount;
798798
return fdNum;
799799
}
800-
void RemoveFd2(struct FSInternal* fs, struct Fd* fd, int i) {
800+
void RemoveFd(struct FSInternal* fs, struct Fd* fd, int i) {
801801
struct BaseINode* inode = fd->inode;
802802
if (inode->nlink == 0)
803803
RemoveINode(fs, inode);
@@ -813,24 +813,6 @@ namespace {
813813
Realloc(fs->fds, fs->fdCount, fs->fdCount - 1);
814814
--fs->fdCount;
815815
}
816-
int RemoveFd(struct FSInternal* fs, unsigned int fd) {
817-
if (fs->fdCount == 0)
818-
return -FS_EBADF;
819-
int low = 0;
820-
int high = fs->fdCount - 1;
821-
while (low <= high) {
822-
int mid = low + ((high - low) / 2);
823-
struct Fd* f = fs->fds[mid];
824-
if (f->fd == fd) {
825-
RemoveFd2(fs, f, mid);
826-
return 0;
827-
}
828-
if (f->fd < fd)
829-
low = mid + 1;
830-
else high = mid - 1;
831-
}
832-
return -FS_EBADF;
833-
}
834816
struct Fd* GetFd(struct FSInternal* fs, unsigned int fdNum) {
835817
if (fs->fdCount == 0)
836818
return NULL;
@@ -1251,7 +1233,22 @@ int FileSystem::Creat(const char* path, fs_mode_t mode) {
12511233
int FileSystem::Close(unsigned int fd) {
12521234
struct FSInternal* fs = (struct FSInternal*)data;
12531235
ScopedLock lock(fs->mtx);
1254-
return RemoveFd(fs, fd);
1236+
if (fs->fdCount == 0)
1237+
return -FS_EBADF;
1238+
int low = 0;
1239+
int high = fs->fdCount - 1;
1240+
while (low <= high) {
1241+
int mid = low + ((high - low) / 2);
1242+
struct Fd* f = fs->fds[mid];
1243+
if (f->fd == fd) {
1244+
RemoveFd(fs, f, mid);
1245+
return 0;
1246+
}
1247+
if (f->fd < fd)
1248+
low = mid + 1;
1249+
else high = mid - 1;
1250+
}
1251+
return -FS_EBADF;
12551252
}
12561253
int FileSystem::CloseRange(unsigned int fd, unsigned int maxFd) {
12571254
if (fd > maxFd)
@@ -1261,11 +1258,11 @@ int FileSystem::CloseRange(unsigned int fd, unsigned int maxFd) {
12611258
for (int i = 0; i != fs->fdCount; ++i) {
12621259
struct Fd* f = fs->fds[i];
12631260
if (f->fd >= fd) {
1264-
RemoveFd2(fs, f, i);
1261+
RemoveFd(fs, f, i);
12651262
while (i != fs->fdCount) {
12661263
f = fs->fds[i];
12671264
if (f->fd < maxFd)
1268-
RemoveFd2(fs, f, i);
1265+
RemoveFd(fs, f, i);
12691266
else break;
12701267
}
12711268
break;
@@ -1694,10 +1691,13 @@ int FileSystem::RenameAt2(
16941691
return res;
16951692
if (oldInode == newInode)
16961693
return 0;
1697-
if (flags & FS_RENAME_NOREPLACE && newInode)
1698-
return -FS_EEXIST;
1699-
if (flags & FS_RENAME_EXCHANGE && !newInode)
1700-
return -FS_ENOENT;
1694+
if (newInode) {
1695+
if (flags & FS_RENAME_NOREPLACE)
1696+
return -FS_EEXIST;
1697+
} else {
1698+
if (flags & FS_RENAME_EXCHANGE)
1699+
return -FS_ENOENT;
1700+
}
17011701
if (FS_S_ISDIR(oldInode->mode)) {
17021702
if (newInode) {
17031703
if (!FS_S_ISDIR(newInode->mode))

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@daisydogs07/filesystem",
3-
"version": "5.2.9",
3+
"version": "5.2.10",
44
"os": ["linux", "win32"],
55
"cpu": ["x64"],
66
"keywords": [

0 commit comments

Comments
 (0)