mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 782117 - part 2: don't save pings that already exist on disk; r=taras
This commit is contained in:
parent
1c8371b1b2
commit
3a151ada0a
@ -27,6 +27,7 @@ const TELEMETRY_DELAY = 60000;
|
|||||||
const PR_WRONLY = 0x2;
|
const PR_WRONLY = 0x2;
|
||||||
const PR_CREATE_FILE = 0x8;
|
const PR_CREATE_FILE = 0x8;
|
||||||
const PR_TRUNCATE = 0x20;
|
const PR_TRUNCATE = 0x20;
|
||||||
|
const PR_EXCL = 0x80;
|
||||||
const RW_OWNER = 0600;
|
const RW_OWNER = 0600;
|
||||||
const RWX_OWNER = 0700;
|
const RWX_OWNER = 0700;
|
||||||
|
|
||||||
@ -817,7 +818,7 @@ TelemetryPing.prototype = {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
savePingToFile: function savePingToFile(ping, file, sync) {
|
savePingToFile: function savePingToFile(ping, file, sync, overwrite) {
|
||||||
let pingString = JSON.stringify(ping);
|
let pingString = JSON.stringify(ping);
|
||||||
|
|
||||||
let converter = Cc["@mozilla.org/intl/scriptableunicodeconverter"]
|
let converter = Cc["@mozilla.org/intl/scriptableunicodeconverter"]
|
||||||
@ -826,8 +827,16 @@ TelemetryPing.prototype = {
|
|||||||
|
|
||||||
let ostream = Cc["@mozilla.org/network/file-output-stream;1"]
|
let ostream = Cc["@mozilla.org/network/file-output-stream;1"]
|
||||||
.createInstance(Ci.nsIFileOutputStream);
|
.createInstance(Ci.nsIFileOutputStream);
|
||||||
ostream.init(file, PR_WRONLY | PR_CREATE_FILE | PR_TRUNCATE,
|
let initFlags = PR_WRONLY | PR_CREATE_FILE | PR_TRUNCATE;
|
||||||
RW_OWNER, ostream.DEFER_OPEN);
|
if (!overwrite) {
|
||||||
|
initFlags |= PR_EXCL;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
ostream.init(file, initFlags, RW_OWNER, ostream.DEFER_OPEN);
|
||||||
|
} catch (e) {
|
||||||
|
// Probably due to PR_EXCL.
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (sync) {
|
if (sync) {
|
||||||
let utf8String = converter.ConvertFromUnicode(pingString);
|
let utf8String = converter.ConvertFromUnicode(pingString);
|
||||||
@ -885,19 +894,22 @@ TelemetryPing.prototype = {
|
|||||||
return file;
|
return file;
|
||||||
},
|
},
|
||||||
|
|
||||||
savePing: function savePing(ping) {
|
savePing: function savePing(ping, overwrite) {
|
||||||
this.savePingToFile(ping, this.saveFileForPing(ping), true);
|
this.savePingToFile(ping, this.saveFileForPing(ping), true, overwrite);
|
||||||
},
|
},
|
||||||
|
|
||||||
savePendingPings: function savePendingPings() {
|
savePendingPings: function savePendingPings() {
|
||||||
this._pendingPings.push(this.getCurrentSessionPayloadAndSlug("saved-session"));
|
let sessionPing = this.getCurrentSessionPayloadAndSlug("saved-session");
|
||||||
this._pendingPings.forEach(function sppcb(e, i, a) { this.savePing(e); }, this);
|
this.savePing(sessionPing, true);
|
||||||
|
this._pendingPings.forEach(function sppcb(e, i, a) {
|
||||||
|
this.savePing(e, false);
|
||||||
|
}, this);
|
||||||
this._pendingPings = [];
|
this._pendingPings = [];
|
||||||
},
|
},
|
||||||
|
|
||||||
saveHistograms: function saveHistograms(file, sync) {
|
saveHistograms: function saveHistograms(file, sync) {
|
||||||
this.savePingToFile(this.getCurrentSessionPayloadAndSlug("saved-session"),
|
this.savePingToFile(this.getCurrentSessionPayloadAndSlug("saved-session"),
|
||||||
file, sync);
|
file, sync, true);
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user