Skip to content

Commit b654bc0

Browse files
committed
Few Changes
* Removed unused arguments * Add default value for `open` in Node.js Module * Don't unzip existing files in "Build and Release" workflow
1 parent 7db8ab4 commit b654bc0

File tree

6 files changed

+22
-28
lines changed

6 files changed

+22
-28
lines changed

.github/workflows/build.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,8 @@ jobs:
154154
- name: Setup NPM Release
155155
if: env.release_exists == 'false'
156156
run: |
157-
unzip -o FileSystem-linux.zip
158-
unzip -o FileSystem-windows.zip
157+
unzip -n FileSystem-linux.zip
158+
unzip -n FileSystem-windows.zip
159159
rm FileSystem-*.zip
160160
161161
- name: Publish to NPM

FileSystem.cc

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1253,8 +1253,8 @@ int FileSystem::Close(unsigned int fd) {
12531253
ScopedLock lock(fs->mtx);
12541254
return RemoveFd(fs, fd);
12551255
}
1256-
int FileSystem::CloseRange(unsigned int fd, unsigned int maxFd, unsigned int flags) {
1257-
if (flags != 0 || fd > maxFd)
1256+
int FileSystem::CloseRange(unsigned int fd, unsigned int maxFd) {
1257+
if (fd > maxFd)
12581258
return -FS_EINVAL;
12591259
struct FSInternal* fs = (struct FSInternal*)data;
12601260
ScopedLock lock(fs->mtx);
@@ -1273,15 +1273,13 @@ int FileSystem::CloseRange(unsigned int fd, unsigned int maxFd, unsigned int fla
12731273
}
12741274
return 0;
12751275
}
1276-
int FileSystem::MkNodAt(int dirFd, const char* path, fs_mode_t mode, fs_dev_t dev) {
1276+
int FileSystem::MkNodAt(int dirFd, const char* path, fs_mode_t mode) {
12771277
if (mode & FS_S_IFMT) {
12781278
if (FS_S_ISDIR(mode))
12791279
return -FS_EPERM;
12801280
if (!FS_S_ISREG(mode))
12811281
return -FS_EINVAL;
12821282
}
1283-
if (dev != 0)
1284-
return -FS_EINVAL;
12851283
struct FSInternal* fs = (struct FSInternal*)data;
12861284
ScopedLock lock(fs->mtx);
12871285
struct DirectoryINode* origCwd = fs->cwd.inode;
@@ -1326,8 +1324,8 @@ int FileSystem::MkNodAt(int dirFd, const char* path, fs_mode_t mode, fs_dev_t de
13261324
parent->ctime = parent->mtime = x->btime;
13271325
return 0;
13281326
}
1329-
int FileSystem::MkNod(const char* path, fs_mode_t mode, fs_dev_t dev) {
1330-
return MkNodAt(FS_AT_FDCWD, path, mode, dev);
1327+
int FileSystem::MkNod(const char* path, fs_mode_t mode) {
1328+
return MkNodAt(FS_AT_FDCWD, path, mode);
13311329
}
13321330
int FileSystem::MkDirAt(int dirFd, const char* path, fs_mode_t mode) {
13331331
struct FSInternal* fs = (struct FSInternal*)data;

FileSystem.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,9 @@ class FS_EXPORT FileSystem {
5050
int Open(const char* path, int flags, fs_mode_t mode);
5151
int Creat(const char* path, fs_mode_t mode);
5252
int Close(unsigned int fd);
53-
int CloseRange(unsigned int fd, unsigned int maxFd, unsigned int flags);
54-
int MkNodAt(int dirFd, const char* path, fs_mode_t mode, fs_dev_t dev);
55-
int MkNod(const char* path, fs_mode_t mode, fs_dev_t dev);
53+
int CloseRange(unsigned int fd, unsigned int maxFd);
54+
int MkNodAt(int dirFd, const char* path, fs_mode_t mode);
55+
int MkNod(const char* path, fs_mode_t mode);
5656
int MkDirAt(int dirFd, const char* path, fs_mode_t mode);
5757
int MkDir(const char* path, fs_mode_t mode);
5858
int SymLinkAt(const char* oldPath, int newDirFd, const char* newPath);

module.cc

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -311,25 +311,26 @@ void FileSystemOpen(const FunctionCallbackInfo<Value>& args) {
311311
Isolate* isolate = args.GetIsolate();
312312
Local<Object> self = args.This()->FindInstanceInPrototypeChain(FSConstructorTmpl.Get(isolate));
313313
THROWIFNOTFS(self, "open");
314-
ASSERT(args.Length() == 3);
314+
ASSERT(args.Length() == 2 || args.Length() == 3);
315315
ASSERT(args[0]->IsString());
316316
ASSERT(IsNumberLike(args[1]));
317-
ASSERT(IsNumberLike(args[2]));
317+
if (args.Length() == 3)
318+
ASSERT(IsNumberLike(args[2]));
318319
FileSystem* fs = reinterpret_cast<FileSystem*>(
319320
self->GetInternalField(0).As<External>()->Value()
320321
);
321322
int res = fs->Open(
322323
*String::Utf8Value(isolate, args[0].As<String>()),
323324
Val<int>(args[1]),
324-
Val<fs_mode_t>(args[2])
325+
args.Length() == 3 ? Val<fs_mode_t>(args[2]) : 0
325326
);
326327
if (res < 0) {
327328
if (res == -FS_ENOMEM) {
328329
isolate->LowMemoryNotification();
329330
res = fs->Open(
330331
*String::Utf8Value(isolate, args[0].As<String>()),
331332
Val<int>(args[1]),
332-
Val<fs_mode_t>(args[2])
333+
args.Length() == 3 ? Val<fs_mode_t>(args[2]) : 0
333334
);
334335
if (res < 0)
335336
THROWERR(res);
@@ -400,8 +401,7 @@ void FileSystemCloseRange(const FunctionCallbackInfo<Value>& args) {
400401
THROWIFERR(
401402
fs->CloseRange(
402403
Val<unsigned int>(args[0]),
403-
Val<unsigned int>(args[1]),
404-
0
404+
Val<unsigned int>(args[1])
405405
)
406406
);
407407
}
@@ -419,17 +419,15 @@ void FileSystemMkNodAt(const FunctionCallbackInfo<Value>& args) {
419419
int res = fs->MkNodAt(
420420
Val<int>(args[0]),
421421
*String::Utf8Value(isolate, args[1].As<String>()),
422-
Val<fs_mode_t>(args[2]),
423-
0
422+
Val<fs_mode_t>(args[2])
424423
);
425424
if (res < 0) {
426425
if (res == -FS_ENOMEM) {
427426
isolate->LowMemoryNotification();
428427
res = fs->MkNodAt(
429428
Val<int>(args[0]),
430429
*String::Utf8Value(isolate, args[1].As<String>()),
431-
Val<fs_mode_t>(args[2]),
432-
0
430+
Val<fs_mode_t>(args[2])
433431
);
434432
if (res < 0)
435433
THROWERR(res);
@@ -448,16 +446,14 @@ void FileSystemMkNod(const FunctionCallbackInfo<Value>& args) {
448446
);
449447
int res = fs->MkNod(
450448
*String::Utf8Value(isolate, args[0].As<String>()),
451-
Val<fs_mode_t>(args[1]),
452-
0
449+
Val<fs_mode_t>(args[1])
453450
);
454451
if (res < 0) {
455452
if (res == -FS_ENOMEM) {
456453
isolate->LowMemoryNotification();
457454
res = fs->MkNod(
458455
*String::Utf8Value(isolate, args[0].As<String>()),
459-
Val<fs_mode_t>(args[1]),
460-
0
456+
Val<fs_mode_t>(args[1])
461457
);
462458
if (res < 0)
463459
THROWERR(res);

module.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ declare module "@daisydogs07/filesystem" {
149149
faccessat(dirFd: NumberLike, path: string, mode: NumberLike): void;
150150
access(path: string, mode: NumberLike): void;
151151
openat(dirFd: NumberLike, path: string, flags: NumberLike, mode: NumberLike): number;
152-
open(path: string, flags: NumberLike, mode: NumberLike): number;
152+
open(path: string, flags: NumberLike, mode?: NumberLike): number;
153153
creat(path: string, mode: NumberLike): number;
154154
close(fd: NumberLike): void;
155155
close_range(fd: NumberLike, maxFd: NumberLike): void;

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.7",
3+
"version": "5.2.8",
44
"os": ["linux", "win32"],
55
"cpu": ["x64"],
66
"main": "./build/Release/module.node",

0 commit comments

Comments
 (0)