本文整理汇总了Java中libcore.io.StructStat类的典型用法代码示例。如果您正苦于以下问题:Java StructStat类的具体用法?Java StructStat怎么用?Java StructStat使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
StructStat类属于libcore.io包,在下文中一共展示了StructStat类的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: removeSpuriousFiles
import libcore.io.StructStat; //导入依赖的package包/类
/**
* Removes files in the systemcache and transfers data dir without corresponding entries in
* the transfers 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 (Constants.LOGV) {
Log.i(Constants.TAG, "in removeSpuriousFiles");
}
// get a list of all files in system cache dir and transfers data dir
List<File> files = new ArrayList<File>();
File[] listOfFiles = mSystemCacheDir.listFiles();
if (listOfFiles != null) {
files.addAll(Arrays.asList(listOfFiles));
}
listOfFiles = mTransferDataDir.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 (LOGV) {
Log.i(Constants.TAG, "in removeSpuriousFiles, preserving file " +
filename);
}
files.remove(new File(filename));
}
}
}
} finally {
if (cursor != null) {
cursor.close();
}
}
// delete files owned by us, but that don't appear in our database
final int myUid = android.os.Process.myUid();
for (File file : files) {
final String path = file.getAbsolutePath();
try {
final StructStat stat = Libcore.os.stat(path);
if (stat.st_uid == myUid) {
if (Constants.LOGVV) {
Log.d(TAG, "deleting spurious file " + path);
}
file.delete();
}
} catch (ErrnoException e) {
Log.w(TAG, "stat(" + path + ") result: " + e);
}
}
}