Skip to content

Commit ddf84e4

Browse files
committed
bump version to 0.2.6 and enhance file download with integrity check and retry logic
1 parent 5138e65 commit ddf84e4

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "office365-service"
3-
version = "0.2.5"
3+
version = "0.2.6"
44
description = "Add your description here"
55
readme = "README.md"
66
authors = [

src/office365_service/sharepoint_service.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,12 @@ def listar_arquivos(self, pasta_alvo: Folder | str):
143143
def obter_arquivo(self, caminho_arquivo: str) -> File | None:
144144
"""Obtém um objeto File a partir do seu caminho relativo no servidor."""
145145
try:
146-
file = self.ctx.web.get_file_by_server_relative_url(caminho_arquivo)
146+
nome_arquivo = os.path.basename(caminho_arquivo)
147+
caminho_arquivo = os.path.dirname(caminho_arquivo)
148+
folder = self.obter_pasta(caminho_arquivo)
149+
if folder is None:
150+
raise FileNotFoundError(f"A pasta '{caminho_arquivo}' não foi encontrada.")
151+
file = folder.files.get_by_url(nome_arquivo)
147152
file.get().execute_query()
148153
return file
149154
except ClientRequestException as e:
@@ -224,7 +229,8 @@ def baixar_arquivo(self, arquivo_sp: File | str, caminho_download: str, max_tent
224229
print(f"Iniciando download de '{file_to_download.name}' (Tentativa {tentativa + 1}/{max_tentativas})...")
225230

226231
with open(caminho_download, "wb") as local_file:
227-
file_to_download.download(local_file).execute_query()
232+
clone_file = self.obter_arquivo(file_to_download.serverRelativeUrl)
233+
local_file.write(clone_file.read())
228234

229235
# Verificação do tamanho do arquivo
230236
tamanho_local = os.path.getsize(caminho_download)

0 commit comments

Comments
 (0)