Skip to content

Commit 20f71b6

Browse files
respect skip params before attempting to remove from icloud #1180 (#1181)
1 parent 7453907 commit 20f71b6

File tree

5 files changed

+329
-280
lines changed

5 files changed

+329
-280
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## Unreleased
44

55
- chore: bump min python version 3.9->3.10
6+
- fix: iCloud clean up with `--keep-icloud-recent-days` does not respect `--skip-*` params [#1180](https://github.com/icloud-photos-downloader/icloud_photos_downloader/issues/1180)
67
- chore: replace build & test platform from retired windows-2019 to windows-2025
78

89
## 1.28.1 (2025-06-08)

src/icloudpd/authentication.py

Lines changed: 50 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -31,64 +31,58 @@ def authenticator(
3131
password_providers: Dict[str, Tuple[Callable[[str], str | None], Callable[[str, str], None]]],
3232
mfa_provider: MFAProvider,
3333
status_exchange: StatusExchange,
34-
) -> Callable[[str, str | None, bool, str | None], PyiCloudService]:
35-
"""Wraping authentication with domain context"""
36-
37-
def authenticate_(
38-
username: str,
39-
cookie_directory: str | None = None,
40-
raise_error_on_2sa: bool = False,
41-
client_id: str | None = None,
42-
) -> PyiCloudService:
43-
"""Authenticate with iCloud username and password"""
44-
logger.debug("Authenticating...")
45-
icloud: PyiCloudService | None = None
46-
_valid_password: str | None = None
34+
username: str,
35+
cookie_directory: str | None = None,
36+
raise_error_on_2sa: bool = False,
37+
client_id: str | None = None,
38+
) -> PyiCloudService:
39+
"""Authenticate with iCloud username and password"""
40+
logger.debug("Authenticating...")
41+
icloud: PyiCloudService | None = None
42+
_valid_password: str | None = None
43+
for _, _pair in password_providers.items():
44+
_reader, _ = _pair
45+
_password = _reader(username)
46+
if _password:
47+
icloud = PyiCloudService(
48+
filename_cleaner,
49+
lp_filename_generator,
50+
domain,
51+
raw_policy,
52+
file_match_policy,
53+
username,
54+
_password,
55+
cookie_directory=cookie_directory,
56+
client_id=client_id,
57+
)
58+
_valid_password = _password
59+
break
60+
61+
if not icloud:
62+
raise NotImplementedError("None of providers gave password")
63+
64+
if _valid_password:
65+
# save valid password to all providers
4766
for _, _pair in password_providers.items():
48-
_reader, _ = _pair
49-
_password = _reader(username)
50-
if _password:
51-
icloud = PyiCloudService(
52-
filename_cleaner,
53-
lp_filename_generator,
54-
domain,
55-
raw_policy,
56-
file_match_policy,
57-
username,
58-
_password,
59-
cookie_directory=cookie_directory,
60-
client_id=client_id,
61-
)
62-
_valid_password = _password
63-
break
67+
_, _writer = _pair
68+
_writer(username, _valid_password)
69+
70+
if icloud.requires_2fa:
71+
if raise_error_on_2sa:
72+
raise TwoStepAuthRequiredError("Two-factor authentication is required")
73+
logger.info("Two-factor authentication is required (2fa)")
74+
if mfa_provider == MFAProvider.WEBUI:
75+
request_2fa_web(icloud, logger, status_exchange)
76+
else:
77+
request_2fa(icloud, logger)
78+
79+
elif icloud.requires_2sa:
80+
if raise_error_on_2sa:
81+
raise TwoStepAuthRequiredError("Two-step authentication is required")
82+
logger.info("Two-step authentication is required (2sa)")
83+
request_2sa(icloud, logger)
6484

65-
if not icloud:
66-
raise NotImplementedError("None of providers gave password")
67-
68-
if _valid_password:
69-
# save valid password to all providers
70-
for _, _pair in password_providers.items():
71-
_, _writer = _pair
72-
_writer(username, _valid_password)
73-
74-
if icloud.requires_2fa:
75-
if raise_error_on_2sa:
76-
raise TwoStepAuthRequiredError("Two-factor authentication is required")
77-
logger.info("Two-factor authentication is required (2fa)")
78-
if mfa_provider == MFAProvider.WEBUI:
79-
request_2fa_web(icloud, logger, status_exchange)
80-
else:
81-
request_2fa(icloud, logger)
82-
83-
elif icloud.requires_2sa:
84-
if raise_error_on_2sa:
85-
raise TwoStepAuthRequiredError("Two-step authentication is required")
86-
logger.info("Two-step authentication is required (2sa)")
87-
request_2sa(icloud, logger)
88-
89-
return icloud
90-
91-
return authenticate_
85+
return icloud
9286

9387

9488
def request_2sa(icloud: PyiCloudService, logger: logging.Logger) -> None:

0 commit comments

Comments
 (0)