fix SMB Usage

This commit is contained in:
jxxghp
2025-07-03 15:21:41 +08:00
parent db40b5105b
commit 82ff7fc090
+6 -33
View File
@@ -516,18 +516,10 @@ class SMB(StorageBase, metaclass=Singleton):
return False return False
def link(self, fileitem: schemas.FileItem, target_file: Path) -> bool: def link(self, fileitem: schemas.FileItem, target_file: Path) -> bool:
""" pass
硬链接文件(SMB不支持,返回False)
"""
logger.warn("【SMB】不支持硬链接操作")
return False
def softlink(self, fileitem: schemas.FileItem, target_file: Path) -> bool: def softlink(self, fileitem: schemas.FileItem, target_file: Path) -> bool:
""" pass
软链接文件(SMB不支持,返回False)
"""
logger.warn("【SMB】不支持软链接操作")
return False
def usage(self) -> Optional[schemas.StorageUsage]: def usage(self) -> Optional[schemas.StorageUsage]:
""" """
@@ -535,33 +527,14 @@ class SMB(StorageBase, metaclass=Singleton):
""" """
try: try:
self._check_connection() self._check_connection()
volume_stat = smbclient.stat_volume(self._server_path)
# 获取磁盘使用情况
try:
stat_result = smbclient.stat(self._server_path)
if hasattr(stat_result, 'f_frsize') and hasattr(stat_result, 'f_blocks'):
block_size = stat_result.f_frsize
total_blocks = stat_result.f_blocks
free_blocks = stat_result.f_bavail
total = total_blocks * block_size
available = free_blocks * block_size
return schemas.StorageUsage( return schemas.StorageUsage(
total=total, total=volume_stat.total_size,
available=available available=volume_stat.caller_available_size
)
except Exception as e:
logger.debug(f"【SMB】获取磁盘使用情况失败: {e}")
# 返回默认值
return schemas.StorageUsage(
total=0,
available=0
) )
except Exception as e: except Exception as e:
logger.error(f"【SMB】获取存储使用情况失败: {e}") logger.error(f"【SMB】获取存储使用情况失败: {e}")
return None return None
def __del__(self): def __del__(self):