Skip to content

Wrong calculation of cache size #81

Description

@bimusiek

I think the calculation of cache size is wrong. When testing, it returned size of a directory without content.
Proper way would be:

const dirSize = async (dir: string) => {
  const files = await FileSystem.statDir(dir);

  const paths = files.map(async (file): Promise<number> => {
    const filePath = `${mainCacheDir}${file.path}`;

    if (file.type === 'directory') {
      return dirSize(filePath);
    }

    return file.size;
  });

  return (await Promise.all(paths)).flat(Infinity).reduce((i, size) => i + size, 0);
};
export async function getCacheSize(): Promise<number> {
  return dirSize(mainCacheDir);
}

I know it is used only to validate if cache dir exists, but in my case I am using it to show the button in the app with cache size and ability to clear cache.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions