public static void cleanupOldPackFiles()

in library/src/main/java/com/whatsapp/stringpacks/StringPacks.java [284:315]


  public static void cleanupOldPackFiles(Context context) {
    File filesDirectory = context.getFilesDir();
    FilenameFilter filenameFilter =
        (dir, name) ->
            name.endsWith(PACK_FILE_EXTENSION) || name.endsWith(TEMP_PACK_FILE_EXTENSION);

    String[] filesNames = filesDirectory.list(filenameFilter);

    if (filesNames != null) {
      for (String fileName : filesNames) {
        String filePrefix = fileName.substring(0, fileName.lastIndexOf(PACK_FILE_EXTENSION));
        String[] splitName = filePrefix.split(UNDERSCORE);
        if (splitName.length > 1) {
          try {
            if (Long.parseLong(splitName[splitName.length - 1])
                != getPackageCodePathTimestamp(context)) {
              SpLog.i("translations/cleanupOldPackFiles Clearing old pack file: " + fileName);
              boolean isDeleted = new File(filesDirectory, fileName).delete();
              if (!isDeleted) {
                SpLog.e(
                    "translations/cleanupOldPackFiles Could not delete old pack file: " + fileName);
              }
            }
          } catch (NumberFormatException e) {
            SpLog.w(
                "translations/cleanupOldPackFiles Pack file name did not contain version info: "
                    + fileName);
          }
        }
      }
    }
  }