Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 17 additions & 5 deletions src/nwb2bids/_converters/_datalad_utils.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,25 @@
import pathlib


def _read_first_bytes(file_path: pathlib.Path, n: int = 6) -> bytes:
def _file_startswith(file_path: pathlib.Path, string: str) -> bool:
"""
Read the first n (by default 6) bytes of a file; necessary for Windows 'symlinks'.
Check if a file starts with a specific string; necessary for Windows 'symlinks'.

Parameters
----------
file_path : pathlib.Path
Path to the file to check.
string : str
String to check if the file starts with.

Returns
-------
bool
True if the file starts with the given string, False otherwise.
"""
with file_path.open(mode="rb") as file_stream:
first_bytes = file_stream.read(n)
return first_bytes
first_bytes = file_stream.read(len(string))
return first_bytes == string.encode("ascii")


def _content_is_retrieved(file_path: pathlib.Path) -> bool:
Expand All @@ -32,4 +44,4 @@ def _content_is_retrieved(file_path: pathlib.Path) -> bool:
if file_path.is_symlink() and (".git" in file_path.readlink().parts):
return True

return _read_first_bytes(file_path=file_path, n=6) != b"/annex"
return not _file_startswith(file_path=file_path, string="/annex")
Loading