Skip to content

Commit

Permalink
Merge branch 'bugfix/fatfsgen-enable-multiple-dots' into 'master'
Browse files Browse the repository at this point in the history
fatfsgen.py: Enable multiple dots in lfn filename

Closes IDF-5969

See merge request espressif/esp-idf!20153
  • Loading branch information
Martin Gano committed Sep 16, 2022
2 parents 740a8b5 + 53c2ea2 commit e9d7340
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
12 changes: 7 additions & 5 deletions components/fatfs/fatfs_utils/fs_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
from .long_filename_utils import (build_lfn_full_name, build_lfn_unique_entry_name_order,
get_required_lfn_entries_count, split_name_to_lfn_entries,
split_name_to_lfn_entry_blocks)
from .utils import (DATETIME, MAX_EXT_SIZE, MAX_NAME_SIZE, FATDefaults, build_lfn_short_entry_name, lfn_checksum,
required_clusters_count, split_content_into_sectors, split_to_name_and_extension)
from .utils import (DATETIME, MAX_EXT_SIZE, MAX_NAME_SIZE, FATDefaults, build_lfn_short_entry_name, build_name,
lfn_checksum, required_clusters_count, split_content_into_sectors, split_to_name_and_extension)


class File:
Expand Down Expand Up @@ -45,7 +45,8 @@ def first_cluster(self, value: Cluster) -> None:
self._first_cluster = value

def name_equals(self, name: str, extension: str) -> bool:
return self.name == name and self.extension == extension
equals_: bool = build_name(name, extension) == build_name(self.name, self.extension)
return equals_

def write(self, content: bytes) -> None:
self.entry.update_content_size(len(content))
Expand Down Expand Up @@ -112,7 +113,8 @@ def first_cluster(self, value: Cluster) -> None:
self._first_cluster = value

def name_equals(self, name: str, extension: str) -> bool:
return self.name == name and self.extension == extension
equals_: bool = build_name(name, extension) == build_name(self.name, self.extension)
return equals_

@property
def entries_count(self) -> int:
Expand Down Expand Up @@ -141,7 +143,7 @@ def init_directory(self) -> None:

def lookup_entity(self, object_name: str, extension: str): # type: ignore
for entity in self.entities:
if entity.name == object_name and entity.extension == extension:
if build_name(entity.name, entity.extension) == build_name(object_name, extension):
return entity
return None

Expand Down
4 changes: 2 additions & 2 deletions components/fatfs/fatfs_utils/long_filename_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from typing import List

from .entry import Entry
from .utils import convert_to_utf16_and_pad
from .utils import build_name, convert_to_utf16_and_pad

# File name with long filenames support can be as long as memory allows. It is split into entries
# holding 13 characters of the filename, thus the number of required entries is ceil(len(long_name) / 13).
Expand Down Expand Up @@ -85,7 +85,7 @@ def build_lfn_full_name(name: str, extension: str) -> str:
The extension is optional, and the long filename entry explicitly specifies it,
on the opposite as for short file names.
"""
lfn_record: str = f'{name}.{extension}' if len(extension) > 0 else name
lfn_record: str = build_name(name, extension)
# the name must be terminated with NULL terminator
# if it doesn't fit into the set of long name directory entries
if len(lfn_record) % Entry.CHARS_PER_ENTRY != 0:
Expand Down
4 changes: 4 additions & 0 deletions components/fatfs/fatfs_utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,10 @@ def read_filesystem(path: str) -> bytearray:
)


def build_name(name: str, extension: str) -> str:
return f'{name}.{extension}' if len(extension) > 0 else name


def build_date_entry(year: int, mon: int, mday: int) -> int:
"""
:param year: denotes year starting from 1980 (0 ~ 1980, 1 ~ 1981, etc), valid values are 1980 + 0..127 inclusive
Expand Down

0 comments on commit e9d7340

Please sign in to comment.