Loading core/java/com/android/internal/util/FileRotator.java +13 −9 Original line number Diff line number Diff line Loading @@ -17,7 +17,7 @@ package com.android.internal.util; import android.os.FileUtils; import android.util.Slog; import android.util.Log; import java.io.BufferedInputStream; import java.io.BufferedOutputStream; Loading @@ -32,7 +32,6 @@ import java.util.zip.ZipEntry; import java.util.zip.ZipOutputStream; import libcore.io.IoUtils; import libcore.io.Streams; /** * Utility that rotates files over time, similar to {@code logrotate}. There is Loading @@ -47,6 +46,8 @@ import libcore.io.Streams; * <p> * Users must periodically call {@link #maybeRotate(long)} to perform actual * rotation. Not inherently thread safe. * * @hide */ public class FileRotator { private static final String TAG = "FileRotator"; Loading Loading @@ -110,7 +111,7 @@ public class FileRotator { if (!name.startsWith(mPrefix)) continue; if (name.endsWith(SUFFIX_BACKUP)) { if (LOGD) Slog.d(TAG, "recovering " + name); if (LOGD) Log.d(TAG, "recovering " + name); final File backupFile = new File(mBasePath, name); final File file = new File( Loading @@ -120,7 +121,7 @@ public class FileRotator { backupFile.renameTo(file); } else if (name.endsWith(SUFFIX_NO_BACKUP)) { if (LOGD) Slog.d(TAG, "recovering " + name); if (LOGD) Log.d(TAG, "recovering " + name); final File noBackupFile = new File(mBasePath, name); final File file = new File( Loading Loading @@ -231,7 +232,7 @@ public class FileRotator { * if the write fails. */ private void rewriteSingle(Rewriter rewriter, String name) throws IOException { if (LOGD) Slog.d(TAG, "rewriting " + name); if (LOGD) Log.d(TAG, "rewriting " + name); final File file = new File(mBasePath, name); final File backupFile; Loading Loading @@ -291,7 +292,7 @@ public class FileRotator { // read file when it overlaps if (info.startMillis <= matchEndMillis && matchStartMillis <= info.endMillis) { if (LOGD) Slog.d(TAG, "reading matching " + name); if (LOGD) Log.d(TAG, "reading matching " + name); final File file = new File(mBasePath, name); readFile(file, reader); Loading Loading @@ -348,7 +349,7 @@ public class FileRotator { if (info.isActive()) { if (info.startMillis <= rotateBefore) { // found active file; rotate if old enough if (LOGD) Slog.d(TAG, "rotating " + name); if (LOGD) Log.d(TAG, "rotating " + name); info.endMillis = currentTimeMillis; Loading @@ -358,7 +359,7 @@ public class FileRotator { } } else if (info.endMillis <= deleteBefore) { // found rotated file; delete if old enough if (LOGD) Slog.d(TAG, "deleting " + name); if (LOGD) Log.d(TAG, "deleting " + name); final File file = new File(mBasePath, name); file.delete(); Loading @@ -383,7 +384,10 @@ public class FileRotator { writer.write(bos); bos.flush(); } finally { FileUtils.sync(fos); try { fos.getFD().sync(); } catch (IOException e) { } IoUtils.closeQuietly(bos); } } Loading Loading
core/java/com/android/internal/util/FileRotator.java +13 −9 Original line number Diff line number Diff line Loading @@ -17,7 +17,7 @@ package com.android.internal.util; import android.os.FileUtils; import android.util.Slog; import android.util.Log; import java.io.BufferedInputStream; import java.io.BufferedOutputStream; Loading @@ -32,7 +32,6 @@ import java.util.zip.ZipEntry; import java.util.zip.ZipOutputStream; import libcore.io.IoUtils; import libcore.io.Streams; /** * Utility that rotates files over time, similar to {@code logrotate}. There is Loading @@ -47,6 +46,8 @@ import libcore.io.Streams; * <p> * Users must periodically call {@link #maybeRotate(long)} to perform actual * rotation. Not inherently thread safe. * * @hide */ public class FileRotator { private static final String TAG = "FileRotator"; Loading Loading @@ -110,7 +111,7 @@ public class FileRotator { if (!name.startsWith(mPrefix)) continue; if (name.endsWith(SUFFIX_BACKUP)) { if (LOGD) Slog.d(TAG, "recovering " + name); if (LOGD) Log.d(TAG, "recovering " + name); final File backupFile = new File(mBasePath, name); final File file = new File( Loading @@ -120,7 +121,7 @@ public class FileRotator { backupFile.renameTo(file); } else if (name.endsWith(SUFFIX_NO_BACKUP)) { if (LOGD) Slog.d(TAG, "recovering " + name); if (LOGD) Log.d(TAG, "recovering " + name); final File noBackupFile = new File(mBasePath, name); final File file = new File( Loading Loading @@ -231,7 +232,7 @@ public class FileRotator { * if the write fails. */ private void rewriteSingle(Rewriter rewriter, String name) throws IOException { if (LOGD) Slog.d(TAG, "rewriting " + name); if (LOGD) Log.d(TAG, "rewriting " + name); final File file = new File(mBasePath, name); final File backupFile; Loading Loading @@ -291,7 +292,7 @@ public class FileRotator { // read file when it overlaps if (info.startMillis <= matchEndMillis && matchStartMillis <= info.endMillis) { if (LOGD) Slog.d(TAG, "reading matching " + name); if (LOGD) Log.d(TAG, "reading matching " + name); final File file = new File(mBasePath, name); readFile(file, reader); Loading Loading @@ -348,7 +349,7 @@ public class FileRotator { if (info.isActive()) { if (info.startMillis <= rotateBefore) { // found active file; rotate if old enough if (LOGD) Slog.d(TAG, "rotating " + name); if (LOGD) Log.d(TAG, "rotating " + name); info.endMillis = currentTimeMillis; Loading @@ -358,7 +359,7 @@ public class FileRotator { } } else if (info.endMillis <= deleteBefore) { // found rotated file; delete if old enough if (LOGD) Slog.d(TAG, "deleting " + name); if (LOGD) Log.d(TAG, "deleting " + name); final File file = new File(mBasePath, name); file.delete(); Loading @@ -383,7 +384,10 @@ public class FileRotator { writer.write(bos); bos.flush(); } finally { FileUtils.sync(fos); try { fos.getFD().sync(); } catch (IOException e) { } IoUtils.closeQuietly(bos); } } Loading