@@ -69,8 +69,7 @@ def ensure_remote_directory(remote_dir):
6969 try :
7070 client .mkdir (remote_dir )
7171 except Exception as e :
72- pass
73-
72+ click .echo (click .style (f"Error ensuring remote directory { remote_dir } : { e } " , fg = "red" ))
7473
7574 for root , _ , files in os .walk (copy_dir ):
7675 for file in files :
@@ -106,15 +105,24 @@ def pull():
106105 elif path .isdir (item_path ):
107106 shutil .rmtree (item_path )
108107
109- # loop through every file and download it
110- # fuck you webdav4 for not having a recursive download function
111- for file in client .ls (remote_path ):
112- remote_file_path = path .join (remote_path , file )
113- local_file_path = path .join (cwd , file )
114- os .makedirs (path .dirname (local_file_path ), exist_ok = True )
115- client .download_file (remote_file_path , local_file_path )
116- click .echo (f"Downloaded: { file } " )
117-
108+ # Recursive function to download all files and directories
109+ def download_recursive (remote_dir , local_dir ):
110+ for item in client .ls (remote_dir ):
111+ if isinstance (item , str ):
112+ continue
113+ elif isinstance (item , dict ):
114+ if item ['type' ] == 'directory' :
115+ os .makedirs (path .join (local_dir , item ['name' ]), exist_ok = True )
116+ download_recursive (path .join (remote_dir , item ['name' ]), path .join (local_dir , item ['name' ]))
117+ else :
118+ remote_file_path = path .join (remote_dir , item ['name' ])
119+ local_file_path = path .join (local_dir , item ['name' ])
120+ client .download_file (remote_file_path , local_file_path )
121+ click .echo (f"Downloaded: { item ['name' ]} " )
122+
123+ # Start the recursive download
124+ download_recursive (remote_path , cwd )
125+
118126 click .echo (click .style ("Pull complete. Local repository updated to latest version." , fg = "green" ))
119127 except Exception as e :
120128 click .echo (click .style (f"Pull failed: { e } " , fg = "red" ))
@@ -128,31 +136,26 @@ def diff():
128136 if path .exists (path .join (cwd , ".kst-git" , "copy" )):
129137 shutil .rmtree (path .join (cwd , ".kst-git" , "copy" ), ignore_errors = True )
130138 remote_path = repo_config ["path" ]
131- # pull from server
132139 click .echo ("Downloading server version..." , color = "yellow" )
133- # loop through every file and download it
134- # fuck you webdav4 for not having a recursive download function
135- def loopThrough (p ):
136- global folder
137- for _ in client .ls (p ):
138- file = ""
139- folder = False
140- if type (_ ) == "str" :
140+
141+ # Recursive function to download all files and directories
142+ def download_recursive (remote_dir , local_dir ):
143+ for item in client .ls (remote_dir ):
144+ if isinstance (item , str ):
141145 continue
142- elif type (_ ) == "dict" :
143- file = _ ["name" ]
144- folder = True
145- if folder :
146- loopThrough (path .join (p , file ))
147- else :
148- remote_file_path = path .join (p , file )
149- local_file_path = path .join (path .join (cwd , ".kst-git" , "copy" ), file )
150- print (local_file_path , remote_file_path )
151- os .makedirs (path .dirname (local_file_path ), exist_ok = True )
152- client .download_file (remote_file_path , local_file_path )
153- click .echo (f"Downloaded: { file } " )
154-
155- loopThrough (remote_path )
146+ elif isinstance (item , dict ):
147+ if item ['type' ] == 'directory' :
148+ os .makedirs (path .join (local_dir , item ['name' ]), exist_ok = True )
149+ download_recursive (path .join (remote_dir , item ['name' ]), path .join (local_dir , item ['name' ]))
150+ else :
151+ remote_file_path = path .join (remote_dir , item ['name' ])
152+ local_file_path = path .join (local_dir , item ['name' ])
153+ client .download_file (remote_file_path , local_file_path )
154+ click .echo (f"Downloaded: { item ['name' ]} " )
155+
156+ # Start the recursive download for diff command
157+ download_recursive (remote_path , path .join (cwd , ".kst-git" , "copy" ))
158+
156159 click .echo ("Comparing local changes..." )
157160
158161 local_dir = cwd
0 commit comments