Skip to content

Commit

Permalink
Pass simplifiedCustomData to fs mkdir call during slimInit. (#23572)
Browse files Browse the repository at this point in the history
## Description
Pass simplifiedCustomData to fs mkdir call during slimInit, to support a
particular AFR use case during container creation, which requires
information from simplifiedCustomData.
This is a follow up change of
#23354
  • Loading branch information
zhajie authored Jan 16, 2025
1 parent 06f5870 commit cfe94f1
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 5 deletions.
5 changes: 5 additions & 0 deletions server/gitrest/packages/gitrest-base/src/utils/definitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*/

import fsPromises from "fs/promises";
import type { MakeDirectoryOptions } from "fs";
import * as git from "@fluidframework/gitresources";

export enum Constants {
Expand Down Expand Up @@ -104,6 +105,10 @@ export interface IFileSystemManagerFactories {
ephemeralFileSystemManagerFactory?: IFileSystemManagerFactory;
}

export interface IFileSystemMakeDirectoryOptions extends MakeDirectoryOptions {
simplifiedCustomData?: string;
}

export interface IStorageRoutingId {
tenantId: string;
documentId: string;
Expand Down
1 change: 1 addition & 0 deletions server/gitrest/packages/gitrest-base/src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export {
IFileSystemManagerFactories,
IFileSystemManagerFactory,
IFileSystemManagerParams,
IFileSystemMakeDirectoryOptions,
IFileSystemPromises,
IRepoManagerParams,
IRepositoryManager,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import {
IExternalWriterConfig,
IFileSystemManager,
IFileSystemManagerFactories,
IFileSystemManagerParams,
IFileSystemMakeDirectoryOptions,
IRepositoryManager,
IStorageDirectoryConfig,
} from "./definitions";
Expand Down Expand Up @@ -397,9 +399,13 @@ export class IsomorphicGitManagerFactory extends RepositoryManagerFactoryBase<vo
);
}

protected async initGitRepo(fs: IFileSystemManager, gitdir: string): Promise<void> {
protected async initGitRepo(
fs: IFileSystemManager,
gitdir: string,
fsParams: IFileSystemManagerParams | undefined,
): Promise<void> {
return this.enableSlimGitInit
? this.slimInit(fs, gitdir)
? this.slimInit(fs, gitdir, fsParams)
: isomorphicGit.init({
fs,
gitdir,
Expand Down Expand Up @@ -442,7 +448,21 @@ export class IsomorphicGitManagerFactory extends RepositoryManagerFactoryBase<vo
*
* This brings file reads from 1 to 0, and writes from 10 to 3.
*/
private async slimInit(fs: IFileSystemManager, gitdir: string): Promise<void> {
private async slimInit(
fs: IFileSystemManager,
gitdir: string,
fsParams: IFileSystemManagerParams | undefined,
): Promise<void> {
const splfCustomData = fsParams?.simplifiedCustomData;
if (splfCustomData) {
// Only pass valid simplifiedCustomData to rootdir in fs mkdir call during slimInit
const mkdirOptions: IFileSystemMakeDirectoryOptions = {
recursive: false,
simplifiedCustomData: splfCustomData,
};
await fs.promises.mkdir(gitdir, mkdirOptions);
}

const folders = ["objects", "refs/heads"].map((dir) => `${gitdir}/${dir}`);
for (const folder of folders) {
await fs.promises.mkdir(folder, { recursive: true });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
Constants,
IFileSystemManager,
IFileSystemManagerFactories,
IFileSystemManagerParams,
IRepoManagerParams,
IRepositoryManager,
IRepositoryManagerFactory,
Expand Down Expand Up @@ -42,7 +43,11 @@ export abstract class RepositoryManagerFactoryBase<TRepo> implements IRepository
) => Promise<IRepositoryManager>;
// Cache repositories to allow for reuse
protected readonly repositoryCache = new Map<string, TRepo>();
protected abstract initGitRepo(fs: IFileSystemManager, gitdir: string): Promise<TRepo>;
protected abstract initGitRepo(
fs: IFileSystemManager,
gitdir: string,
fsParams: IFileSystemManagerParams | undefined,
): Promise<TRepo>;
protected abstract openGitRepo(gitdir: string): Promise<TRepo>;
protected abstract createRepoManager(
fileSystemManager: IFileSystemManager,
Expand Down Expand Up @@ -81,7 +86,11 @@ export abstract class RepositoryManagerFactoryBase<TRepo> implements IRepository
lumberjackBaseProperties: Record<string, any>,
) => {
// Create and then cache the repository
const repository = await this.initGitRepo(fileSystemManager, gitdir);
const repository = await this.initGitRepo(
fileSystemManager,
gitdir,
params.fileSystemManagerParams,
);
this.repositoryCache.set(repoPath, repository);
Lumberjack.info("Created a new repo", {
...lumberjackBaseProperties,
Expand Down

0 comments on commit cfe94f1

Please sign in to comment.