API to check if a filesystem is an FAT filesystem on windows

This commit is contained in:
Kovid Goyal 2022-07-14 13:43:40 +05:30
parent 1a0706d9d3
commit 41ade135aa
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
3 changed files with 27 additions and 3 deletions

View File

@ -16,7 +16,7 @@ import shutil
import sys import sys
import time import time
import uuid import uuid
from contextlib import suppress, closing from contextlib import closing, suppress
from functools import partial from functools import partial
from calibre import as_unicode, force_unicode, isbytestring, prints from calibre import as_unicode, force_unicode, isbytestring, prints
@ -40,8 +40,8 @@ from calibre.utils.config import from_json, prefs, to_json, tweaks
from calibre.utils.date import EPOCH, parse_date, utcfromtimestamp, utcnow from calibre.utils.date import EPOCH, parse_date, utcfromtimestamp, utcnow
from calibre.utils.filenames import ( from calibre.utils.filenames import (
WindowsAtomicFolderMove, ascii_filename, atomic_rename, copyfile_using_links, WindowsAtomicFolderMove, ascii_filename, atomic_rename, copyfile_using_links,
copytree_using_links, hardlink_file, is_case_sensitive, remove_dir_if_empty, copytree_using_links, hardlink_file, is_case_sensitive, is_fat_filesystem,
samefile remove_dir_if_empty, samefile
) )
from calibre.utils.formatter_functions import ( from calibre.utils.formatter_functions import (
compile_user_template_functions, formatter_functions, compile_user_template_functions, formatter_functions,
@ -470,6 +470,7 @@ class DB:
if not os.path.exists(self.library_path): if not os.path.exists(self.library_path):
os.makedirs(self.library_path) os.makedirs(self.library_path)
self.is_case_sensitive = is_case_sensitive(self.library_path) self.is_case_sensitive = is_case_sensitive(self.library_path)
self.is_fat_filesystem = is_fat_filesystem(self.library_path)
SchemaUpgrade(self, self.library_path, self.field_metadata) SchemaUpgrade(self, self.library_path, self.field_metadata)

View File

@ -189,6 +189,10 @@ class Cache:
def dbpath(self): def dbpath(self):
return self.backend.dbpath return self.backend.dbpath
@property
def is_fat_filesystem(self):
return self.backend.is_fat_filesystem
@property @property
def safe_read_lock(self): def safe_read_lock(self):
''' A safe read lock is a lock that does nothing if the thread already ''' A safe read lock is a lock that does nothing if the thread already

View File

@ -604,6 +604,25 @@ if iswindows:
if len(path) > 200 and os.path.isabs(path) and not path.startswith(long_path_prefix): if len(path) > 200 and os.path.isabs(path) and not path.startswith(long_path_prefix):
path = long_path_prefix + os.path.normpath(path) path = long_path_prefix + os.path.normpath(path)
return path return path
def is_fat_filesystem(path):
try:
from calibre_extensions.winutil import filesystem_type_name
except ImportError:
return False
if not path:
return False
drive = os.path.abspath(path)[0].upper()
try:
tn = filesystem_type_name(f'{drive}:\\')
except OSError:
return False
# Values I have seen: FAT32, exFAT, NTFS
return tn.upper().startswith('FAT')
else: else:
def make_long_path_useable(path): def make_long_path_useable(path):
return path return path
def is_fat_filesystem(path):
# TODO: Implement for Linux and macOS
return False