Lock* IxManager_make_snapshot_read_lock(IndexManager *self, const CharBuf *filename) { ZombieCharBuf *lock_name = ZCB_WRAP(filename); LockFactory *lock_factory = S_obtain_lock_factory(self); if ( !CB_Starts_With_Str(filename, "snapshot_", 9) || !CB_Ends_With_Str(filename, ".json", 5) ) { THROW(ERR, "Not a snapshot filename: %o", filename); } // Truncate ".json" from end of snapshot file name. ZCB_Chop(lock_name, sizeof(".json") - 1); return LockFact_Make_Shared_Lock(lock_factory, (CharBuf*)lock_name, 1000, 100); }
static Folder* S_enclosing_folder(Folder *self, ZombieCharBuf *path) { size_t path_component_len = 0; uint32_t code_point; // Strip trailing slash. if (ZCB_Code_Point_From(path, 0) == '/') { ZCB_Chop(path, 1); } // Find first component of the file path. ZombieCharBuf *scratch = ZCB_WRAP((CharBuf*)path); ZombieCharBuf *path_component = ZCB_WRAP((CharBuf*)path); while (0 != (code_point = ZCB_Nip_One(scratch))) { if (code_point == '/') { ZCB_Truncate(path_component, path_component_len); ZCB_Nip(path, path_component_len + 1); break; } path_component_len++; } // If we've eaten up the entire filepath, self is enclosing folder. if (ZCB_Get_Size(scratch) == 0) { return self; } Folder *local_folder = Folder_Local_Find_Folder(self, (CharBuf*)path_component); if (!local_folder) { /* This element of the filepath doesn't exist, or it's not a * directory. However, there are filepath characters left over, * implying that this component ought to be a directory -- so the * original file path is invalid. */ return NULL; } // This file path component is a folder. Recurse into it. return S_enclosing_folder(local_folder, path); }