return;
}
XmlUtils.writeMapXml(mcr.mapToWriteToDisk, str);
+ FileUtils.sync(str);
str.close();
setFilePermissionsFromMode(mFile.getPath(), mMode, 0);
FileStatus stat = new FileStatus();
* @return volume ID or -1
*/
public static native int getFatVolumeId(String mountPoint);
-
+
+ /**
+ * Perform an fsync on the given FileOutputStream. The stream at this
+ * point must be flushed but not yet closed.
+ */
+ public static boolean sync(FileOutputStream stream) {
+ try {
+ if (stream != null) {
+ stream.getFD().sync();
+ }
+ return true;
+ } catch (IOException e) {
+ }
+ return false;
+ }
+
// copy a file from srcFile to destFile, return true if succeed, return
// false if fail
public static boolean copyFile(File srcFile, File destFile) {
if (destFile.exists()) {
destFile.delete();
}
- OutputStream out = new FileOutputStream(destFile);
+ FileOutputStream out = new FileOutputStream(destFile);
try {
byte[] buffer = new byte[4096];
int bytesRead;
out.write(buffer, 0, bytesRead);
}
} finally {
+ out.flush();
+ try {
+ out.getFD().sync();
+ } catch (IOException e) {
+ }
out.close();
}
return true;
public void finishWrite(FileOutputStream str) {
if (str != null) {
+ FileUtils.sync(str);
try {
str.close();
mBackupName.delete();
public void failWrite(FileOutputStream str) {
if (str != null) {
+ FileUtils.sync(str);
try {
str.close();
mBaseName.delete();
public void truncate() throws IOException {
try {
FileOutputStream fos = new FileOutputStream(mBaseName);
+ FileUtils.sync(fos);
fos.close();
} catch (FileNotFoundException e) {
throw new IOException("Couldn't append " + mBaseName);
import android.net.TrafficStats;
import android.os.BatteryManager;
import android.os.BatteryStats;
+import android.os.FileUtils;
import android.os.Handler;
import android.os.Message;
import android.os.Parcel;
FileOutputStream stream = new FileOutputStream(mFile.chooseForWrite());
stream.write(next.marshall());
stream.flush();
+ FileUtils.sync(stream);
stream.close();
mFile.commit();
} catch (IOException e) {
FileOutputStream fos = new FileOutputStream(keyFile);
fos.write(retKey);
fos.flush();
+ FileUtils.sync(fos);
fos.close();
FileUtils.setPermissions(keyFile.getName(), (FileUtils.S_IRUSR | FileUtils.S_IWUSR),
-1, -1);
import android.content.pm.PackageManager;
import android.os.BatteryManager;
import android.os.Binder;
+import android.os.FileUtils;
import android.os.IBinder;
import android.os.DropBoxManager;
import android.os.RemoteException;
dumpFile = new File(DUMPSYS_DATA_PATH + BATTERY_STATS_SERVICE_NAME + ".dump");
dumpStream = new FileOutputStream(dumpFile);
batteryInfoService.dump(dumpStream.getFD(), DUMPSYS_ARGS);
- dumpStream.getFD().sync();
+ FileUtils.sync(dumpStream);
// add dump file to drop box
db.addFile("BATTERY_DISCHARGE_INFO", dumpFile, DropBoxManager.IS_TEXT);
import android.net.Uri;
import android.os.Debug;
import android.os.DropBoxManager;
+import android.os.FileUtils;
import android.os.Handler;
import android.os.ParcelFileDescriptor;
import android.os.StatFs;
int bufferSize = mBlockSize;
if (bufferSize > 4096) bufferSize = 4096;
if (bufferSize < 512) bufferSize = 512;
- output = new BufferedOutputStream(new FileOutputStream(temp), bufferSize);
+ FileOutputStream foutput = new FileOutputStream(temp);
+ output = new BufferedOutputStream(foutput, bufferSize);
if (read == buffer.length && ((flags & DropBoxManager.IS_GZIPPED) == 0)) {
output = new GZIPOutputStream(output);
flags = flags | DropBoxManager.IS_GZIPPED;
read = input.read(buffer);
if (read <= 0) {
+ FileUtils.sync(foutput);
output.close(); // Get a final size measurement
output = null;
} else {
private void extractPublicFiles(PackageParser.Package newPackage,
File publicZipFile) throws IOException {
- final ZipOutputStream publicZipOutStream =
- new ZipOutputStream(new FileOutputStream(publicZipFile));
+ final FileOutputStream fstr = new FileOutputStream(publicZipFile);
+ final ZipOutputStream publicZipOutStream = new ZipOutputStream(fstr);
final ZipFile privateZip = new ZipFile(newPackage.mPath);
// Copy manifest, resources.arsc and res directory to public zip
}
}
+ publicZipOutStream.finish();
+ publicZipOutStream.flush();
+ FileUtils.sync(fstr);
publicZipOutStream.close();
FileUtils.setPermissions(
publicZipFile.getAbsolutePath(),
mPastSignatures.clear();
try {
- BufferedOutputStream str = new BufferedOutputStream(new FileOutputStream(
- mSettingsFilename));
+ FileOutputStream fstr = new FileOutputStream(mSettingsFilename);
+ BufferedOutputStream str = new BufferedOutputStream(fstr);
//XmlSerializer serializer = XmlUtils.serializerInstance();
XmlSerializer serializer = new FastXmlSerializer();
serializer.endDocument();
str.flush();
+ FileUtils.sync(fstr);
str.close();
// New settings successfully written, old ones are no longer
File tempFile = new File(mPackageListFilename.toString() + ".tmp");
JournaledFile journal = new JournaledFile(mPackageListFilename, tempFile);
- str = new BufferedOutputStream(new FileOutputStream(journal.chooseForWrite()));
+ fstr = new FileOutputStream(journal.chooseForWrite());
+ str = new BufferedOutputStream(fstr);
try {
StringBuilder sb = new StringBuilder();
for (PackageSetting pkg : mPackages.values()) {
str.write(sb.toString().getBytes());
}
str.flush();
+ FileUtils.sync(fstr);
str.close();
journal.commit();
}
import android.content.res.Resources;
import android.os.Binder;
import android.os.Bundle;
+import android.os.FileUtils;
import android.os.IBinder;
import android.os.RemoteException;
import android.os.FileObserver;
} catch (IOException ex) {}
}
if (fos != null) {
+ FileUtils.sync(fos);
try {
fos.close();
} catch (IOException ex) {}
Slog.w(TAG, "Failure writing last done pre-boot receivers", e);
file.delete();
} finally {
+ FileUtils.sync(fos);
if (dos != null) {
try {
dos.close();
import android.os.Binder;
import android.os.IBinder;
import com.android.internal.os.PkgUsageStats;
+
+import android.os.FileUtils;
import android.os.Parcel;
import android.os.Process;
import android.os.ServiceManager;
out.recycle();
stream.flush();
} finally {
+ FileUtils.sync(stream);
stream.close();
}
}