1616PLACEHOLDER_FILE = "file"
1717
1818
19- def touch_access_time (path , access_time : "float | None" = None ):
19+ def touch_access_time (path , access_time : "float | None" = None , strict = True ):
2020 """Update access time of file.
2121
2222 Returns the new access time.
@@ -27,7 +27,7 @@ def touch_access_time(path, access_time: "float | None" = None):
2727
2828 p = Path (path )
2929
30- if not p .exists ():
30+ if not p .exists () and not strict :
3131 p .touch ()
3232
3333 stat = p .stat ()
@@ -64,6 +64,7 @@ def _make_local_details(self, path):
6464 # note that this is called in ._open(), at the point it's known the file
6565 # will be cached
6666 fn = super ()._make_local_details (path )
67+ print (f"cache file: { fn } " )
6768 Path (fn ).parent .mkdir (parents = True , exist_ok = True )
6869
6970 return fn
@@ -72,7 +73,7 @@ def hash_name(self, path, same_name):
7273 # the main change in this function is that, for same_name, it returns
7374 # the full path
7475 if same_name :
75- if self .hash_prefix :
76+ if self .hash_prefix is not None :
7677 # optionally make the name relative to a parent path
7778 # using the hash of parent path as a prefix, to flatten a bit
7879 suffix = Path (path ).relative_to (Path (self .hash_prefix ))
@@ -87,10 +88,37 @@ def hash_name(self, path, same_name):
8788
8889 return path
8990 else :
90- return hash_name ( path , same_name )
91+ raise NotImplementedError ( )
9192
92- def touch_access_time (path ):
93- return touch_access_time (path )
93+
94+ class PinsRscCache (PinsCache ):
95+ """Modifies the PinsCache to allow hash_prefix to be an RSC server url.
96+
97+ Note that this class also modifies the first / in a path to be a -, so that
98+ pin contents will not be put into subdirectories, for e.g. michael/mtcars/data.txt.
99+ """
100+
101+ protocol = "pinsrsccache"
102+
103+ def hash_name (self , path , same_name ):
104+ # the main change in this function is that, for same_name, it returns
105+ # the full path
106+ if same_name :
107+ if self .hash_prefix is None :
108+ raise NotImplementedError ()
109+
110+ # change pin path of form <user>/<content> to <user>+<content>
111+ suffix = path .replace ("/" , "+" , 1 )
112+ prefix = hash_name (self .hash_prefix , False )
113+
114+ # TODO: hacky to automatically tack on protocol here
115+ # but this is what R pins boards do. Could make a bool arg?
116+ proto_name = protocol_to_string (self .fs .protocol )
117+ full_prefix = "_" .join ([proto_name , prefix ])
118+ return str (full_prefix / Path (suffix ))
119+
120+ else :
121+ raise NotImplementedError ()
94122
95123
96124class PinsUrlCache (PinsCache ):
0 commit comments