Skip to content

Commit 6c340bb

Browse files
committed
Cleaned up unused per-account directories left over from old versions.
1 parent 2113e33 commit 6c340bb

1 file changed

Lines changed: 41 additions & 0 deletions

File tree

TMessagesProj/src/main/java/org/telegram/messenger/ApplicationLoader.java

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,47 @@ public void onReceive(Context context, Intent intent) {
261261
ContactsController.getInstance(a).checkAppAccount();
262262
DownloadController.getInstance(a);
263263
}
264+
265+
Utilities.globalQueue.postRunnable(ApplicationLoader::cleanupUnusedAccountDirs);
266+
}
267+
268+
private static void cleanupUnusedAccountDirs() {
269+
SharedPreferences prefs = applicationContext.getSharedPreferences("fork_cleanup", Context.MODE_PRIVATE);
270+
if (prefs.getBoolean("empty_account_dirs_cleaned_v1", false)) {
271+
return;
272+
}
273+
try {
274+
File filesDir = getFilesDirFixed();
275+
int deleted = 0;
276+
for (int a = 1; a < UserConfig.MAX_ACCOUNT_COUNT; a++) {
277+
if (UserConfig.getInstance(a).isClientActivated()) {
278+
continue;
279+
}
280+
File accountDir = new File(filesDir, "account" + a);
281+
if (accountDir.exists() && accountDir.isDirectory() && deleteRecursively(accountDir)) {
282+
deleted++;
283+
}
284+
}
285+
if (BuildVars.LOGS_ENABLED) {
286+
FileLog.d("Cleaned up " + deleted + " unused account directories");
287+
}
288+
} catch (Exception e) {
289+
FileLog.e(e);
290+
} finally {
291+
prefs.edit().putBoolean("empty_account_dirs_cleaned_v1", true).apply();
292+
}
293+
}
294+
295+
private static boolean deleteRecursively(File file) {
296+
if (file.isDirectory()) {
297+
File[] children = file.listFiles();
298+
if (children != null) {
299+
for (File child : children) {
300+
deleteRecursively(child);
301+
}
302+
}
303+
}
304+
return file.delete();
264305
}
265306

266307
public ApplicationLoader() {

0 commit comments

Comments
 (0)