@@ -19,7 +19,35 @@ pub fn should(config: &Config) -> Result<bool, Box<dyn Error>> {
1919 }
2020}
2121
22- pub async fn replace ( config : & Config , conn : & mut Connection ) -> Result < ( ) , Box < dyn Error > > {
22+ // doesn’t replace pantry clone, will build db
23+ // essential for working in a local pantry clone with PKGX_PANTRY_DIR set
24+ pub async fn ensure ( config : & Config , conn : & mut Connection ) -> Result < ( ) , Box < dyn Error > > {
25+ if !config. pantry_dir . join ( "projects" ) . is_dir ( ) {
26+ replace ( config, conn) . await
27+ } else {
28+ let dest = & config. pantry_dir ;
29+ std:: fs:: create_dir_all ( dest. clone ( ) ) ?;
30+ let dir = OpenOptions :: new ( )
31+ . read ( true ) // Open in read-only mode; no need to write.
32+ . open ( dest) ?;
33+ dir. lock_exclusive ( ) ?;
34+
35+ pantry_db:: cache ( config, conn) ?;
36+
37+ FileExt :: unlock ( & dir) ?;
38+
39+ Ok ( ( ) )
40+ }
41+ }
42+
43+ pub async fn update ( config : & Config , conn : & mut Connection ) -> Result < ( ) , Box < dyn Error > > {
44+ if std:: env:: var ( "PKGX_PANTRY_DIR" ) . is_ok ( ) {
45+ return Err ( "PKGX_PANTRY_DIR is set, refusing to update pantry" ) ?;
46+ }
47+ replace ( config, conn) . await
48+ }
49+
50+ async fn replace ( config : & Config , conn : & mut Connection ) -> Result < ( ) , Box < dyn Error > > {
2351 let url = env ! ( "PKGX_PANTRY_TARBALL_URL" ) ;
2452 let dest = & config. pantry_dir ;
2553
0 commit comments