File tree Expand file tree Collapse file tree 2 files changed +20
-1
lines changed
Expand file tree Collapse file tree 2 files changed +20
-1
lines changed Original file line number Diff line number Diff line change @@ -134,6 +134,19 @@ def uploadchannel( # noqa: C901
134134 config .PROGRESS_MANAGER .set_tree (create_initial_tree (channel ))
135135 tree = config .PROGRESS_MANAGER .tree
136136
137+ # Early permission check: Try creating the channel before downloading/uploading files
138+ # This will fail fast if the user lacks edit permissions
139+ # Fixes issues #95 and #434 by avoiding wasted downloads/uploads
140+ if (
141+ config .PROGRESS_MANAGER .get_status_val () <= Status .CREATE_TREE .value
142+ and command != "dryrun"
143+ ):
144+ config .LOGGER .info ("Checking channel permissions..." )
145+ try :
146+ tree .root_id , tree .channel_id = tree .add_channel ()
147+ except Exception :
148+ sys .exit (1 )
149+
137150 # Download files if they haven't been downloaded already
138151 if config .PROGRESS_MANAGER .get_status_val () <= Status .DOWNLOAD_FILES .value :
139152 config .LOGGER .info ("" )
Original file line number Diff line number Diff line change @@ -30,6 +30,8 @@ def __init__(self, channel):
3030 self .failed_uploads = {}
3131 self .file_map = {}
3232 self .all_nodes = []
33+ self .root_id = None # Will be set during early permission check
34+ self .channel_id = None # Will be set during early permission check
3335
3436 def validate (self ):
3537 """validate: checks if tree structure is valid
@@ -269,7 +271,11 @@ def upload_tree(self):
269271 from datetime import datetime
270272
271273 start_time = datetime .now ()
272- root , channel_id = self .add_channel ()
274+ # Use cached root_id and channel_id if already set (from early permission check)
275+ if self .root_id is not None and self .channel_id is not None :
276+ root , channel_id = self .root_id , self .channel_id
277+ else :
278+ root , channel_id = self .add_channel ()
273279 self .node_count_dict = {"upload_count" : 0 , "total_count" : self .channel .count ()}
274280
275281 config .LOGGER .info ("\t Preparing fields..." )
You can’t perform that action at this time.
0 commit comments