自己放某个文件到/cache分区,重启后发现文件消失了,那么是怎么消失的呢?【转】
自己放某个文件到/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 dir
- List<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 database
- for (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_FILE
- String 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_PREFIX
- String[] 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_ 开头的文件了
自己放某个文件到/cache分区,重启后发现文件消失了,那么是怎么消失的呢?【转】相关推荐
- java 下载后删除,在服务器端生成文件后,下载后并删除,改了后发现文件变成空白解决思路...
当前位置:我的异常网» Java Web开发 » 在服务器端生成文件后,下载后并删除,改了后发现文件 在服务器端生成文件后,下载后并删除,改了后发现文件变成空白解决思路 www.myexception ...
- 电脑蓝屏重启后,js文件损坏或断电重启后文件损坏
问题来源:电脑蓝屏,重新用编译软件打开(我用的是优化过的eclipse,自称是内部工具/滑稽),发现js文件变成了空白,再次打开文件所在位置,打开文件,还是一样,重启电脑,重启编译工具没用.文件显示3 ...
- 服务器重启后发现docker-compose的nginx重启失败: Error starting userland proxy: listen tcp 0.0.0.0:80: bind: addres
服务器重启后执行docker-compose up -d报错: Starting nginx ... php is up-to-date Starting nginx ... errorERROR: ...
- 如何恢复计算机中被隐藏的文件夹,电脑中病毒后,文件与文件夹被隐藏,如何恢复正常显示。...
电脑中病毒后,文件与文件夹被隐藏,右键属性中[隐藏]复选框为灰色,恢复正常显示方法如下: [开始]-[运行]-输入:CMD,进入命令行窗口: 1.进入目录: cd d: 2.取消本目录下所有文件与文件 ...
- git clone 只有.git文件夹 git status后发现文件夹全都被删除了
近期在拉代码的时候,发现了个问题,拉下来的代码一致都报错,然后只有一个.git文件夹,使用git status发现,所有的文件都被删除了,根据系统提示的 **git restore --source= ...
- 关于解决windows10运行机械硬盘中的游戏时遭遇死机重启后硬盘消失的方法
事情的起因是:当在windows10中运行机械硬盘F盘的英雄联盟客户端时出现死机,用任务管理器也无法解决时,直接关机重启. 特点:重启后发现开机很慢,F盘消失了,并且电脑变得很卡,每次点开一个应用进程 ...
- 高通平台修改Cache分区大小
文档说明 本文档以SC826-CN-01(MSM8953平台)为例,描述如何修改Android系统的Cache分区大小. 默认代码Cache分区大小为256M,下面我们修改为512M. 相关文件路径 ...
- 计算机启动后桌面丢失,重启电脑后桌面excel会丢失sheet | 电脑重启后,桌面图标资料文件,全部不见了怎么办?...
电脑重启时,提示是否保存一个桌面excel文件,点击保存,重启后,文件丢失,急 求助 系统被破坏或篡改,桌面启动项丢失,试述办法去排除. 1击桌面空白处-排列图标-点选显面图标. 2.在桌面上右键点击 ...
- 云服务器重启后网站打不开及FTP连不上的原因及解决方法
安装好CENTOS 6.5 后 并安装了NGINX+MYSQL+PHP后,设置好网站,访问正常,但重启后发现网站打不开了,登录服务器,测试nginx -t 测试正常,说明服务都正常,后来发现是因为防 ...
最新文章
- 为啥现在4位单片机依然没有被淘汰?4位单片机还有用的吗?
- 从技术到科学,中国AI向何处去?
- 64位系统识别内存 服务器,服务器内存和电脑内存的区别
- mvvm模式和mvc的区别_mvvm 和 mvc 区别?
- nginx反向代理https站点
- 缓存和字符串相互转换
- 前端网址导航-最酷前端圈子在这里
- 牛客 - 收集纸片(最短哈密顿路径-状压dp)
- java怎么注销cookie_java web中cookie的永久创建与撤销
- 机器人编程语言学习哪门最好?5大热门编程语言推荐
- 编程语言的“别样”编年史
- IIS7日志文件位置
- HDU ACM Steps攻略 ACM Steps的全部内容
- 包装类转换基本数据类型与基本数据类型转换为包装类
- 正则表达式: input框禁止输入空格:不能只有空格、不能有空格、不能为空的判断
- LeetCode 1616. 分割两个字符串得到回文串
- 百度视觉技术部实习生招聘
- 本地修改服务器上的内容,本地修改指向服务器
- Linux系统基础入门
- 微信H5页面前端开发,大多数人都会遇到的几个兼容性坑