@@ -216,55 +216,41 @@ def maybe_copy_files(path: Path | str, include_files: bool) -> tuple[str, str]:
216216    hash  =  get_hash (path , include_files )
217217    print ("path: " , path , "Hash: " , hash )
218218
219-     # To avoid unnecessary work when the same file is included multiple times, 
220-     # use a directory scoped by a hash of the file. 
221-     tmp_folder  =  os .path .join (
222-         os .path .basename (path ), tempfile .gettempdir (), "shiny_include_files" 
223-     )
224-     tmpdir  =  os .path .join (tmp_folder , hash )
219+     tmpdir  =  os .path .join (tempfile .gettempdir (), f"shiny_include_files_{ hash }  )
225220    path_dest  =  os .path .join (tmpdir , os .path .basename (path ))
226-     print ("path_dest:" , path_dest )
227-     print (tmp_folder )
228-     os .chmod (tmp_folder , 0o755 )
221+     print ("tmpdir: " , tmpdir , "path_dest: " , path_dest )
229222
223+     # To avoid unnecessary work when the same file is included multiple times, 
224+     # use a directory scoped by a hash of the file. 
230225    # Since the hash/tmpdir should represent all the files in the path's directory, 
231226    # we can check if it exists to determine if we have a cache hit 
232227    if  os .path .exists (path_dest ):
233228        print ("Path already exists:" , path_dest )
234229        return  path_dest , hash 
235230
236231    # Otherwise, make sure we have a clean slate 
237-     if  os .path .exists (tmpdir ):
232+     if  os .path .exists (path_dest ):
238233        print ("Folder already exists, but not files, removing." )
239-         shutil .rmtree (tmpdir )
234+         shutil .rmtree (path_dest )
240235
241-     # This recursively changes permissions to 755 (owner rwx, other rx) for all files 
242-     # under `tmp/unique_hash` so that the app can be run by other collaborators 
243-     # on a multi-tenant system. See #2061 
244236    if  include_files :
237+         print (
238+             "Copying all included files from: " ,
239+             path ,
240+             " with perms: " ,
241+             oct (os .stat (path ).st_mode ),
242+         )
245243        shutil .copytree (os .path .dirname (path ), tmpdir )
246-         for  dirpath , dirs , filenames  in  os .walk (tmpdir ):
247-             # set perms on files 
248-             for  file  in  filenames :
249-                 os .chmod (os .path .join (dirpath , file ), 0o755 )
250-                 print (
251-                     "File: " ,
252-                     file ,
253-                     "File perms: " ,
254-                     oct (os .stat (os .path .join (dirpath , file )).st_mode ),
255-                 )
244+ 
256245    else :
257-         os .makedirs (tmpdir , mode = 0o755 , exist_ok = True )
246+         os .makedirs (path_dest , mode = 0o755 , exist_ok = True )
258247        print (
259248            "Copying files from: " ,
260249            path ,
261250            " with perms: " ,
262251            oct (os .stat (path ).st_mode ),
263252        )
264253        shutil .copy (path , path_dest )
265-         os .chmod (path_dest , 0o755 )
266-         print ("File: " , path_dest , "perms" , oct (os .stat (path_dest ).st_mode ))
267- 
268254    return  path_dest , hash 
269255
270256
0 commit comments