Skip to content

Commit 737bf11

Browse files
authored
Run black after a version update
PR #36
2 parents 92c862b + 06855a3 commit 737bf11

File tree

9 files changed

+102
-24
lines changed

9 files changed

+102
-24
lines changed

.github/workflows/ci.yml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ on:
44
push:
55
pull_request:
66

7+
env:
8+
winfsp_version: "1.12.22339"
9+
710
jobs:
811

912
Quality:
@@ -18,6 +21,7 @@ jobs:
1821

1922
runs-on: windows-latest
2023
strategy:
24+
fail-fast: false
2125
matrix:
2226
python_version: [cp36, cp37, cp38, cp39, cp310, cp311]
2327
architecture: [win32, win_amd64]
@@ -27,13 +31,13 @@ jobs:
2731
uses: actions/checkout@v2
2832

2933
- name: Install winfsp
30-
run: choco install winfsp -y --version=1.10.22006
34+
run: choco install winfsp -y --version=${{ env.winfsp_version }}
3135

3236
- name: Download winfsp-tests-x86
3337
uses: engineerd/configurator@v0.0.6
3438
with:
3539
name: winfsp-tests-x86.exe
36-
url: https://github.com/winfsp/winfsp/releases/download/v1.10/winfsp-tests-1.10.22006.zip
40+
url: https://github.com/winfsp/winfsp/releases/download/v${{ env.winfsp_version }}/winfsp-tests-${{ env.winfsp_version }}.zip
3741
pathInArchive: winfsp-tests-x86.exe
3842

3943
- name: Run cibuildwheel for ${{ matrix.python_version }}-${{ matrix.architecture }}
@@ -65,7 +69,7 @@ jobs:
6569
uses: actions/checkout@v2
6670

6771
- name: Install winfsp
68-
run: choco install winfsp -y --version=1.8.20304
72+
run: choco install winfsp -y --version=${{ env.winfsp_version }}
6973

7074
- name: Set up Python
7175
uses: actions/setup-python@v2

src/winfspy/file_system.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
import os
2+
import time
3+
import errno
4+
15
from .plumbing import ffi, lib, cook_ntstatus, nt_success, file_system_interface_trampoline_factory
26
from .plumbing import WinFSPyError, FileSystemAlreadyStarted, FileSystemNotStarted
37
from .operations import BaseFileSystemOperations
@@ -150,7 +154,10 @@ def _create_file_system(self):
150154
device_path = lib.WFSPY_FSP_FSCTL_DISK_DEVICE_NAME
151155

152156
result = lib.FspFileSystemCreate(
153-
device_path, self._volume_params, self._file_system_interface, self._file_system_ptr,
157+
device_path,
158+
self._volume_params,
159+
self._file_system_interface,
160+
self._file_system_ptr,
154161
)
155162
if not nt_success(result):
156163
raise WinFSPyError(f"Cannot create file system: {cook_ntstatus(result).name}")
@@ -173,6 +180,21 @@ def start(self):
173180
result = lib.FspFileSystemStartDispatcher(self._file_system_ptr[0], 0)
174181
if not nt_success(result):
175182
raise WinFSPyError(f"Cannot start file system dispatcher: {cook_ntstatus(result).name}")
183+
# Since winfsp 1.12.22301 (2022-2), the file system might not be reachable as soon as the dispatcher is started.
184+
# Instead a request might fail with the following error:
185+
# [WinError 995] The I/O operation has been aborted because of either a thread exit or an application request
186+
# In order to avoid this issue, we simply stat the mountpoint until it responds, with a maximum of 10 attempts.
187+
attemps = 10
188+
delay = 0.01 # seconds
189+
for i in range(attemps):
190+
try:
191+
os.stat(self.mountpoint)
192+
break
193+
except OSError as e:
194+
if e.errno == errno.EINVAL and e.winerror in (995, 1005):
195+
time.sleep(delay)
196+
continue
197+
raise
176198

177199
def restart(self, **volume_params):
178200
self.stop()

src/winfspy/memfs.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -195,15 +195,19 @@ def __init__(self, volume_label, read_only=False):
195195
def _create_directory(self, path):
196196
path = self._root_path / path
197197
obj = FolderObj(
198-
path, FILE_ATTRIBUTE.FILE_ATTRIBUTE_DIRECTORY, self._root_obj.security_descriptor,
198+
path,
199+
FILE_ATTRIBUTE.FILE_ATTRIBUTE_DIRECTORY,
200+
self._root_obj.security_descriptor,
199201
)
200202
self._entries[path] = obj
201203

202204
def _import_files(self, file_path):
203205
file_path = Path(file_path)
204206
path = self._root_path / file_path.name
205207
obj = FileObj(
206-
path, FILE_ATTRIBUTE.FILE_ATTRIBUTE_ARCHIVE, self._root_obj.security_descriptor,
208+
path,
209+
FILE_ATTRIBUTE.FILE_ATTRIBUTE_ARCHIVE,
210+
self._root_obj.security_descriptor,
207211
)
208212
self._entries[path] = obj
209213
obj.write(file_path.read_bytes(), 0, False)
@@ -270,7 +274,10 @@ def create(
270274
)
271275
else:
272276
file_obj = self._entries[file_name] = FileObj(
273-
file_name, file_attributes, security_descriptor, allocation_size,
277+
file_name,
278+
file_attributes,
279+
security_descriptor,
280+
allocation_size,
274281
)
275282

276283
return OpenedObj(file_obj)

src/winfspy/operations.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,10 @@ def ll_overwrite(
252252
cooked_file_context = ffi.from_handle(file_context)
253253
try:
254254
self.overwrite(
255-
cooked_file_context, file_attributes, replace_file_attributes, allocation_size,
255+
cooked_file_context,
256+
file_attributes,
257+
replace_file_attributes,
258+
allocation_size,
256259
)
257260

258261
except NTStatusError as exc:
@@ -261,7 +264,11 @@ def ll_overwrite(
261264
return self.ll_get_file_info(file_context, file_info)
262265

263266
def overwrite(
264-
self, file_context, file_attributes, replace_file_attributes: bool, allocation_size: int,
267+
self,
268+
file_context,
269+
file_attributes,
270+
replace_file_attributes: bool,
271+
allocation_size: int,
265272
) -> None:
266273
raise NotImplementedError()
267274

@@ -350,7 +357,11 @@ def ll_write(
350357

351358
try:
352359
p_bytes_transferred[0] = self.write(
353-
cooked_file_context, cooked_buffer, offset, write_to_end_of_file, constrained_io,
360+
cooked_file_context,
361+
cooked_buffer,
362+
offset,
363+
write_to_end_of_file,
364+
constrained_io,
354365
)
355366

356367
except NTStatusError as exc:

src/winfspy/plumbing/file_system_interface.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@ def _trampolin_fs_GetSecurityByName(
2323
):
2424
user_context = ffi.from_handle(FileSystem.UserContext)
2525
return user_context.ll_get_security_by_name(
26-
FileName, PFileAttributesOrReparsePointIndex, SecurityDescriptor, PSecurityDescriptorSize,
26+
FileName,
27+
PFileAttributesOrReparsePointIndex,
28+
SecurityDescriptor,
29+
PSecurityDescriptorSize,
2730
)
2831

2932

@@ -60,7 +63,12 @@ def _trampolin_fs_Open(FileSystem, FileName, CreateOptions, GrantedAccess, PFile
6063

6164
@ffi.def_extern()
6265
def _trampolin_fs_Overwrite(
63-
FileSystem, FileContext, FileAttributes, ReplaceFileAttributes, AllocationSize, FileInfo,
66+
FileSystem,
67+
FileContext,
68+
FileAttributes,
69+
ReplaceFileAttributes,
70+
AllocationSize,
71+
FileInfo,
6472
):
6573
user_context = ffi.from_handle(FileSystem.UserContext)
6674
return user_context.ll_overwrite(
@@ -188,7 +196,13 @@ def _trampolin_fs_ReadDirectory(
188196

189197
@ffi.def_extern()
190198
def _trampolin_fs_ResolveReparsePoints(
191-
FileSystem, FileName, ReparsePointIndex, ResolveLastPathComponent, PIoStatus, Buffer, PSize,
199+
FileSystem,
200+
FileName,
201+
ReparsePointIndex,
202+
ResolveLastPathComponent,
203+
PIoStatus,
204+
Buffer,
205+
PSize,
192206
):
193207
user_context = ffi.from_handle(FileSystem.UserContext)
194208
return user_context.ll_resolve_reparse_points(

src/winfspy/plumbing/get_winfsp_dir.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,5 +61,5 @@ def get_winfsp_bin_dir():
6161
def get_winfsp_library_name():
6262
# See:
6363
# https://docs.python.org/3/library/platform.html#platform.architecture
64-
is_64bits = sys.maxsize > 2 ** 32
64+
is_64bits = sys.maxsize > 2**32
6565
return "winfsp-" + ("x64" if is_64bits else "x86")

src/winfspy/plumbing/win32_filetime.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,10 @@ def filetime_to_dt(ft):
9898
>>> assert dt_to_filetime(filetime_to_dt(now)) == now, now
9999
"""
100100
milliseconds = (ft - EPOCH_AS_FILETIME) // MILLISEDCONDS_TO_HNS
101-
return datetime.fromtimestamp(milliseconds / MILLISECONDS, timezone.utc,)
101+
return datetime.fromtimestamp(
102+
milliseconds / MILLISECONDS,
103+
timezone.utc,
104+
)
102105

103106

104107
def filetime_now():

src/winfspy/tests/fixtures.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@ def pytest_addoption(parser):
1414
help="A path to the file system to test",
1515
)
1616
parser.addoption(
17-
"--enable-stream-tests", action="store_true", default=False, help="Enable stream tests",
17+
"--enable-stream-tests",
18+
action="store_true",
19+
default=False,
20+
help="Enable stream tests",
1821
)
1922
# Options already added (via the pluging module)
2023
except ValueError:

src/winfspy/tests/winfstest/test_winfs.py

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,11 @@ def create_file(
106106
security_attributes = win32security.SECURITY_ATTRIBUTES()
107107
security_attributes.bInheritHandle = 0
108108
if sddl:
109-
security_attributes.SECURITY_DESCRIPTOR = win32security.ConvertStringSecurityDescriptorToSecurityDescriptor(
110-
sddl, win32security.SDDL_REVISION_1,
109+
security_attributes.SECURITY_DESCRIPTOR = (
110+
win32security.ConvertStringSecurityDescriptorToSecurityDescriptor(
111+
sddl,
112+
win32security.SDDL_REVISION_1,
113+
)
111114
)
112115

113116
# Windows API call
@@ -172,8 +175,11 @@ def create_directory(path, sddl):
172175
security_attributes = win32security.SECURITY_ATTRIBUTES()
173176
security_attributes.bInheritHandle = 0
174177
if sddl:
175-
security_attributes.SECURITY_DESCRIPTOR = win32security.ConvertStringSecurityDescriptorToSecurityDescriptor(
176-
sddl, win32security.SDDL_REVISION_1,
178+
security_attributes.SECURITY_DESCRIPTOR = (
179+
win32security.ConvertStringSecurityDescriptorToSecurityDescriptor(
180+
sddl,
181+
win32security.SDDL_REVISION_1,
182+
)
177183
)
178184

179185
# Windows API call
@@ -213,7 +219,9 @@ def set_end_of_file(path, length):
213219
# Second windows API call
214220
assert handle != win32file.INVALID_HANDLE_VALUE
215221
win32file.SetFileInformationByHandle(
216-
handle, SYMBOLS.FileEndOfFileInfo, length,
222+
handle,
223+
SYMBOLS.FileEndOfFileInfo,
224+
length,
217225
)
218226

219227
# Close the handle
@@ -251,7 +259,10 @@ def prepare(x):
251259
# Second windows API call
252260
assert handle != win32file.INVALID_HANDLE_VALUE
253261
win32file.SetFileTime(
254-
handle, creation_time, last_access_time, last_write_time,
262+
handle,
263+
creation_time,
264+
last_access_time,
265+
last_write_time,
255266
)
256267

257268
# Close the handle
@@ -280,7 +291,8 @@ def get_file_security(path, info):
280291
def set_file_security(path, info, sddl):
281292
# Create security descriptor
282293
descriptor = win32security.ConvertStringSecurityDescriptorToSecurityDescriptor(
283-
sddl, win32security.SDDL_REVISION_1,
294+
sddl,
295+
win32security.SDDL_REVISION_1,
284296
)
285297

286298
# Windows api call
@@ -428,7 +440,9 @@ def runner(fn, *args, **kwargs):
428440

429441

430442
@pytest.mark.parametrize(
431-
"test_module_path", TEST_MODULES, ids=[path.name for path in TEST_MODULES],
443+
"test_module_path",
444+
TEST_MODULES,
445+
ids=[path.name for path in TEST_MODULES],
432446
)
433447
def test_winfs(test_module_path, file_system_path, process_runner):
434448
parser = partial(parse_argument, file_system_path)

0 commit comments

Comments
 (0)