@@ -89,6 +89,10 @@ def include_js(
8989 if method == "inline" :
9090 return tags .script (read_utf8 (file_path ), ** kwargs )
9191
92+ # QUESTION: Do we have access to the session or user at this point? Can write based on that and then give them full perms?
93+ # Where does cleanup happen?! Seems like maybe that needs to be included before we make new folders? Check the date? Tell if active
94+ # session using them?!
95+
9296 include_files = method == "link_files"
9397 path_dest , hash = maybe_copy_files (file_path , include_files )
9498
@@ -217,21 +221,35 @@ def maybe_copy_files(path: Path | str, include_files: bool) -> tuple[str, str]:
217221
218222 # To avoid unnecessary work when the same file is included multiple times,
219223 # use a directory scoped by a hash of the file.
224+ # We need to make tempdir deterministic if we use the pythong TemporaryDirectory class so we can still tell if the hash has changed
225+ # We want the temp dir unique to the process, hash should be the only thing that is dynamic based on the file contents.
226+ # Cleanup done using __del__?
227+ # Also make perms so that others can read it
228+ # Double check clean-up based on process ending
220229 tmpdir = os .path .join (tempfile .gettempdir (), "shiny_include_files" , hash )
221230 path_dest = os .path .join (tmpdir , os .path .basename (path ))
231+ print ("tmpdir, path_dest: " , tmpdir , path_dest )
222232
223233 # Since the hash/tmpdir should represent all the files in the path's directory,
224234 # we can simply return here
225235 if os .path .exists (path_dest ):
236+ print ("path exists: " , path_dest , hash )
226237 return path_dest , hash
227238
228239 # Otherwise, make sure we have a clean slate
240+ # We only hit this if tempdir/ exists but not the file (i.e. style.css)
229241 if os .path .exists (tmpdir ):
242+ print ("clean the slate, tmpdir" , tmpdir )
230243 shutil .rmtree (tmpdir )
231244
232245 if include_files :
246+ print ("include files true" )
247+ # TODO: Switch this to tempfile.mkdtmp? This will scope perms to the userID
248+ # QUESTION what is the user id? The system user? How does that work in Connect?
233249 shutil .copytree (os .path .dirname (path ), tmpdir )
234250 else :
251+ print ("include files false" )
252+ # This should probably use the temp file syntax
235253 os .makedirs (tmpdir , exist_ok = True )
236254 shutil .copy (path , path_dest )
237255
@@ -240,11 +258,14 @@ def maybe_copy_files(path: Path | str, include_files: bool) -> tuple[str, str]:
240258
241259def get_hash (path : Path | str , include_files : bool ) -> str :
242260 if include_files :
243- key = get_file_key (path )
244- else :
245261 dir = os .path .dirname (path )
262+ # This is recursively listing everything in the dir and making that part of the hash even though we're not pulling it over
263+ # Ex. we make a hash, we copy over one file, then we jsut don't keep going
246264 files = glob .iglob (os .path .join (dir , "**" ), recursive = True )
247265 key = "\n " .join ([get_file_key (x ) for x in files ])
266+ else :
267+ key = get_file_key (path )
268+
248269 return hash_deterministic (key )
249270
250271
0 commit comments