Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions ricecooker/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,19 @@ def uploadchannel( # noqa: C901
config.PROGRESS_MANAGER.set_tree(create_initial_tree(channel))
tree = config.PROGRESS_MANAGER.tree

# Early permission check: Try creating the channel before downloading/uploading files
# This will fail fast if the user lacks edit permissions
# Fixes issues #95 and #434 by avoiding wasted downloads/uploads
if (
config.PROGRESS_MANAGER.get_status_val() <= Status.CREATE_TREE.value
and command != "dryrun"
):
config.LOGGER.info("Checking channel permissions...")
try:
tree.root_id, tree.channel_id = tree.add_channel()
except Exception:
sys.exit(1)

# Download files if they haven't been downloaded already
if config.PROGRESS_MANAGER.get_status_val() <= Status.DOWNLOAD_FILES.value:
config.LOGGER.info("")
Expand Down
8 changes: 7 additions & 1 deletion ricecooker/managers/tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ def __init__(self, channel):
self.failed_uploads = {}
self.file_map = {}
self.all_nodes = []
self.root_id = None # Will be set during early permission check
self.channel_id = None # Will be set during early permission check

def validate(self):
"""validate: checks if tree structure is valid
Expand Down Expand Up @@ -269,7 +271,11 @@ def upload_tree(self):
from datetime import datetime

start_time = datetime.now()
root, channel_id = self.add_channel()
# Use cached root_id and channel_id if already set (from early permission check)
if self.root_id is not None and self.channel_id is not None:
root, channel_id = self.root_id, self.channel_id
else:
root, channel_id = self.add_channel()
Comment on lines +274 to +278
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just out of curiosity. Would there be any state when we reach this point, but the add_channel hasn't been called yet?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would really hope not - but maybe if someone subclassed the tree manager somewhere and overrode the place we do the initial check?

self.node_count_dict = {"upload_count": 0, "total_count": self.channel.count()}

config.LOGGER.info("\tPreparing fields...")
Expand Down
Loading