Android: /cache中的文件是怎么消失的

news/2024/11/24 20:45:33/

自己放某个文件到/cache分区,重启后发现文件消失了,那么是怎么消失的呢?


Step 1. 

packages\providers\DownloadProvider\src\com\android\providers\downloads\StorageManager.java:

    /*** Removes files in the systemcache and downloads data dir without corresponding entries in* the downloads database.* This can occur if a delete is done on the database but the file is not removed from the* filesystem (due to sudden death of the process, for example).* This is not a very common occurrence. So, do this only once in a while.*/private void removeSpuriousFiles() {if (true || Constants.LOGV) {Log.i(Constants.TAG, "in removeSpuriousFiles");}// get a list of all files in system cache dir and downloads data dirList<File> files = new ArrayList<File>();File[] listOfFiles = mSystemCacheDir.listFiles();if (listOfFiles != null) {files.addAll(Arrays.asList(listOfFiles));}listOfFiles = mDownloadDataDir.listFiles();if (listOfFiles != null) {files.addAll(Arrays.asList(listOfFiles));}if (files.size() == 0) {return;}Cursor cursor = mContext.getContentResolver().query(Downloads.Impl.ALL_DOWNLOADS_CONTENT_URI,new String[] { Downloads.Impl._DATA }, null, null, null);try {if (cursor != null) {while (cursor.moveToNext()) {String filename = cursor.getString(0);if (!TextUtils.isEmpty(filename)) {if (true || Constants.LOGV) {Log.i(Constants.TAG, "in removeSpuriousFiles, preserving file " +filename);}files.remove(new File(filename));}}}} finally {if (cursor != null) {cursor.close();}}// delete the files not found in the databasefor (File file : files) {if (file.getName().equals(Constants.KNOWN_SPURIOUS_FILENAME) ||file.getName().equalsIgnoreCase(Constants.RECOVERY_DIRECTORY)) {continue;}if (true || Constants.LOGV) {Log.i(Constants.TAG, "deleting spurious file " + file.getAbsolutePath());}file.delete();}}
    /** A magic filename that is allowed to exist within the system cache */public static final String KNOWN_SPURIOUS_FILENAME = "lost+found";/** A magic filename that is allowed to exist within the system cache */public static final String RECOVERY_DIRECTORY = "recovery";

除 lost+found, recovery这两个目录外的文件都删掉


Setp 2.

frameworks\base\core\java\android\os\RecoverySystem.java:

    /*** Called after booting to process and remove recovery-related files.* @return the log file from recovery, or null if none was found.** @hide*/public static String handleAftermath() {// Record the tail of the LOG_FILEString log = null;try {log = FileUtils.readTextFile(LOG_FILE, -LOG_FILE_MAX_LENGTH, "...\n");} catch (FileNotFoundException e) {Log.i(TAG, "No recovery log file");} catch (IOException e) {Log.e(TAG, "Error reading recovery log", e);}// Delete everything in RECOVERY_DIR except those beginning// with LAST_PREFIXString[] names = RECOVERY_DIR.list();for (int i = 0; names != null && i < names.length; i++) {if (names[i].startsWith(LAST_PREFIX)) continue;File f = new File(RECOVERY_DIR, names[i]);if (!f.delete()) {Log.e(TAG, "Can't delete: " + f);} else {Log.i(TAG, "Deleted: " + f);}}return log;}
private static String LAST_PREFIX = "last_";
/cache/recovery目录中,除last_开头的文件都删掉


------------------------------------------------

开机走完这两步后幸存的文件只有 /cache/lost+found目录中的文件,及/cache/recovery/last_ 开头的文件了





 


http://www.ppmy.cn/news/507025.html

相关文章

浏览器缓存Cache

首先缓存的优点是&#xff1a;缓解服务端压力&#xff1b;快。 强缓存和协商缓存 强缓存是从本地缓存数据表中去取资源&#xff0c;不向服务端发送请求&#xff1b;协商缓存意思是每次使用缓存前都要和服务端进行确认。 从Response Header的Cache-Control的值看缓存规则&…

各种浏览器的缓存文件的位置和修改缓存目录的方法

一、手动清空缓存1、Opera清除Opera浏览器的缓存的方法&#xff1a;打开Opera&#xff0c;工具->首选项->高级->历史->点击立即清空按钮就可以清除Opera浏览器的缓存。2、IE浏览器的缓存清空打开IE浏览器&#xff0c;工具->Internet选项->常规->Internet临…

Android 获取cache缓存的目录路径

转发请备注原文地址&#xff1a;https://www.niwoxuexi.com/blog/android00/article/224.html Android开发中&#xff0c;有时需要知道cache缓存的路径。我写了一个静态类&#xff0c;供大家能参考 public class CommonUtil {/*** 获取cache路径** param context* return*/pu…

cache是什么文件?

转自&#xff1a;https://zhidao.baidu.com/question/27865855.html 通常人们所说的Cache就是指缓存SRAM。 SRAM叫静态内存&#xff0c;“静态”指的是当我们将一笔数据写入SRAM后&#xff0c;除非重新写入新数据或关闭电源&#xff0c;否则写入的数据保持不变。 由于CPU的速度…

Vue中的cache缓存,原来是这样啊

上篇文章写了arrify转数组&#xff0c;无论传给arrify什么样的数据都是返回一个数组&#xff0c;相对而言还是比较简单的。这篇文章分享一个比较有意思的东西&#xff0c;那就是Vue中如何实现cache缓存的。提前揭晓答案–闭包。下面我们就来手写一个吧。第一步&#xff0c;毫无…

各种浏览器的cache文件夹

Windows xp firefox&#xff1a; c:\Documents and Settings\administrator\Application Data\Mozilla\Firefox\Profiles chrome: C:\Documents and Settings\Administrator\Local Settings\Application Data\Google\Chrome\User Data\Default\Cache IE:(360等国内浏览器) …

DNDC模型四:土壤碳储量与作物产量、农田减排潜力分析

查看原文>>>双碳目标下DNDC模型建模方法及在土壤碳储量、温室气体排放、农田减排、土地变化、气候变化中的实践应用 由于全球变暖、大气中温室气体浓度逐年增加等问题的出现&#xff0c;“双碳”行动特别是碳中和已经在世界范围形成广泛影响。国家领导人在多次重要会…

二层网络和三层网络的区别

大家经常可以听到二层网络、三层网络的说法&#xff0c;我们这里提到的二层、三层是按照逻辑拓扑结构进行的分类&#xff0c;并不是ISO七层模型中的数据链路层和网络层&#xff0c;而是指核心层、汇聚层和接入层。这三层都部署的就是三层网络结构&#xff0c;二层网络结构没有汇…