@photostructure/fs-metadata 1.4.0 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -27,6 +27,10 @@ public:
27
27
  }
28
28
 
29
29
  void Execute() override {
30
+ if (IsShuttingDown()) {
31
+ SetError("fs-metadata: shutdown in progress");
32
+ return;
33
+ }
30
34
  try {
31
35
  DEBUG_LOG("[LinuxMetadataWorker] starting statvfs for %s",
32
36
  mountPoint.c_str());
@@ -181,4 +185,4 @@ Napi::Value GetVolumeMetadata(const Napi::CallbackInfo &info) {
181
185
  return deferred.Promise();
182
186
  }
183
187
 
184
- } // namespace FSMeta
188
+ } // namespace FSMeta
@@ -1,6 +1,7 @@
1
1
  // src/windows/hidden.cpp
2
2
  #include "hidden.h"
3
3
  #include "../common/debug_log.h"
4
+ #include "../common/shutdown.h"
4
5
  #include "error_utils.h"
5
6
  #include "security_utils.h"
6
7
 
@@ -36,14 +37,14 @@ public:
36
37
  };
37
38
  } // anonymous namespace
38
39
 
39
- class GetHiddenWorker : public Napi::AsyncWorker {
40
+ class GetHiddenWorker : public SafeAsyncWorker {
40
41
  const std::string path;
41
42
  bool result = false;
42
43
  Napi::Promise::Deferred deferred;
43
44
 
44
45
  public:
45
46
  GetHiddenWorker(Napi::Env env, std::string p, Napi::Promise::Deferred def)
46
- : Napi::AsyncWorker(env), path(std::move(p)), deferred(def) {}
47
+ : SafeAsyncWorker(env), path(std::move(p)), deferred(def) {}
47
48
 
48
49
  void Execute() override {
49
50
  try {
@@ -104,17 +105,17 @@ public:
104
105
  DEBUG_LOG("[GetHiddenWorker] OnOK called, result=%s",
105
106
  result ? "true" : "false");
106
107
  Napi::HandleScope scope(Env());
107
- deferred.Resolve(Napi::Boolean::New(Env(), result));
108
+ SafeResolve(deferred, Napi::Boolean::New(Env(), result));
108
109
  }
109
110
 
110
111
  void OnError(const Napi::Error &e) override {
111
112
  DEBUG_LOG("[GetHiddenWorker] OnError called with: %s", e.Message().c_str());
112
113
  Napi::HandleScope scope(Env());
113
- deferred.Reject(e.Value());
114
+ SafeReject(deferred, e.Value());
114
115
  }
115
116
  };
116
117
 
117
- class SetHiddenWorker : public Napi::AsyncWorker {
118
+ class SetHiddenWorker : public SafeAsyncWorker {
118
119
  const std::string path;
119
120
  const bool value;
120
121
  Napi::Promise::Deferred deferred;
@@ -122,7 +123,7 @@ class SetHiddenWorker : public Napi::AsyncWorker {
122
123
  public:
123
124
  SetHiddenWorker(Napi::Env env, std::string p, bool v,
124
125
  Napi::Promise::Deferred def)
125
- : Napi::AsyncWorker(env), path(std::move(p)), value(v), deferred(def) {}
126
+ : SafeAsyncWorker(env), path(std::move(p)), value(v), deferred(def) {}
126
127
 
127
128
  void Execute() override {
128
129
  try {
@@ -144,12 +145,12 @@ public:
144
145
 
145
146
  void OnOK() override {
146
147
  Napi::HandleScope scope(Env());
147
- deferred.Resolve(Napi::Boolean::New(Env(), true));
148
+ SafeResolve(deferred, Napi::Boolean::New(Env(), true));
148
149
  }
149
150
 
150
151
  void OnError(const Napi::Error &e) override {
151
152
  Napi::HandleScope scope(Env());
152
- deferred.Reject(e.Value());
153
+ SafeReject(deferred, e.Value());
153
154
  }
154
155
  };
155
156
 
@@ -195,4 +196,4 @@ Napi::Promise SetHiddenAttribute(const Napi::CallbackInfo &info) {
195
196
  }
196
197
  }
197
198
 
198
- } // namespace FSMeta
199
+ } // namespace FSMeta
@@ -154,6 +154,10 @@ private:
154
154
  VolumeMetadataOptions options_;
155
155
 
156
156
  void Execute() override {
157
+ if (IsShuttingDown()) {
158
+ SetError("fs-metadata: shutdown in progress");
159
+ return;
160
+ }
157
161
  try {
158
162
  // Get drive status first
159
163
  DriveStatus status = CheckDriveStatus(mountPoint);
@@ -250,4 +254,4 @@ Napi::Value GetVolumeMetadata(const Napi::CallbackInfo &info) {
250
254
  return deferred.Promise();
251
255
  }
252
256
 
253
- } // namespace FSMeta
257
+ } // namespace FSMeta
@@ -2,6 +2,7 @@
2
2
  #include "../common/volume_mount_points.h"
3
3
  #include "../common/debug_log.h"
4
4
  #include "../common/error_utils.h"
5
+ #include "../common/shutdown.h"
5
6
  #include "drive_status.h"
6
7
  #include "fs_meta.h"
7
8
  #include "security_utils.h"
@@ -21,7 +22,7 @@ struct DriveStringsBuffer {
21
22
  : buffer(std::make_unique<WCHAR[]>(size)) {}
22
23
  };
23
24
 
24
- class GetVolumeMountPointsWorker : public Napi::AsyncWorker {
25
+ class GetVolumeMountPointsWorker : public SafeAsyncWorker {
25
26
 
26
27
  private:
27
28
  Napi::Promise::Deferred deferred_;
@@ -31,10 +32,14 @@ private:
31
32
  public:
32
33
  GetVolumeMountPointsWorker(const Napi::Promise::Deferred &deferred,
33
34
  uint32_t timeoutMs = 5000)
34
- : Napi::AsyncWorker(deferred.Env()), deferred_(deferred),
35
+ : SafeAsyncWorker(deferred.Env()), deferred_(deferred),
35
36
  timeoutMs_(timeoutMs) {}
36
37
 
37
38
  void Execute() override {
39
+ if (IsShuttingDown()) {
40
+ SetError("fs-metadata: shutdown in progress");
41
+ return;
42
+ }
38
43
  try {
39
44
  DEBUG_LOG("[GetVolumeMountPoints] getting logical drive strings size");
40
45
  DWORD size = GetLogicalDriveStringsW(0, nullptr);
@@ -74,12 +79,19 @@ public:
74
79
  }
75
80
 
76
81
  // Check all drive statuses in parallel
82
+ if (IsShuttingDown()) {
83
+ return;
84
+ }
77
85
  auto statuses = CheckDriveStatus(paths, timeoutMs_);
78
86
 
79
87
  // Build mount points from results
80
88
  mountPoints_.reserve(paths.size());
81
89
 
82
90
  for (size_t i = 0; i < paths.size(); i++) {
91
+ if (IsShuttingDown()) {
92
+ return;
93
+ }
94
+
83
95
  MountPoint mp;
84
96
  mp.mountPoint = paths[i];
85
97
  mp.status = DriveStatusToString(statuses[i]);
@@ -115,6 +127,7 @@ public:
115
127
  }
116
128
 
117
129
  void OnOK() override {
130
+ Napi::HandleScope scope(Env());
118
131
  auto env = Env();
119
132
  Napi::Array result = Napi::Array::New(env, mountPoints_.size());
120
133
 
@@ -122,7 +135,12 @@ public:
122
135
  result[i] = mountPoints_[i].ToObject(env);
123
136
  }
124
137
 
125
- deferred_.Resolve(result);
138
+ SafeResolve(deferred_, result);
139
+ }
140
+
141
+ void OnError(const Napi::Error &error) override {
142
+ Napi::HandleScope scope(Env());
143
+ SafeReject(deferred_, error.Value());
126
144
  }
127
145
 
128
146
  }; // class GetVolumeMountPointsWorker
@@ -140,4 +158,4 @@ Napi::Promise GetVolumeMountPoints(const Napi::CallbackInfo &info) {
140
158
  worker->Queue();
141
159
  return deferred.Promise();
142
160
  }
143
- } // namespace FSMeta
161
+ } // namespace FSMeta