@@ -8,15 +8,14 @@ const {classes: Cc, interfaces: Ci, utils: Cu} = Components;
88
99const Services =
1010 globalThis . Services ||
11- Cu . import ( "resource://gre/modules/Services.jsm" ) . Services ;
12- const { Log } = importLocal ( "resource://gre/modules/Log.jsm" ) ;
13- const { Preferences } = importLocal ( "resource://gre/modules/Preferences.jsm" ) ;
14- const { FileUtils } = importLocal ( "resource://gre/modules/FileUtils.jsm" ) ;
15- const { OS } = importLocal ( "resource://gre/modules/osfile.jsm" ) ;
11+ Cu . import ( "resource://gre/modules/Services.sys.mjs" ) . Services ;
12+ const { Log } = ChromeUtils . importESModule ( "resource://gre/modules/Log.sys.mjs" ) ;
13+ const { Preferences } = ChromeUtils . importESModule ( "resource://gre/modules/Preferences.sys.mjs" ) ;
14+ const { FileUtils } = ChromeUtils . importESModule ( "resource://gre/modules/FileUtils.sys.mjs" ) ;
1615const { Downloads } = importLocal ( "resource://gre/modules/Downloads.jsm" ) ;
1716const { Config } = importLocal ( "chrome://aboutsync/content/config.js" ) ;
1817const { Panel, PanelGroup } = require ( "./panel" ) ;
19- const { Weave } = importLocal ( "resource://services-sync/main.js " ) ;
18+ const { Weave } = ChromeUtils . importESModule ( "resource://services-sync/main.sys.mjs " ) ;
2019
2120// For our "Sync Preferences" support.
2221// A "log level" <select> element.
@@ -244,10 +243,10 @@ class LogFilesComponent extends React.Component {
244243
245244 async downloadFile ( sourceFileURI , targetFilename ) {
246245 let downloadsDir = await Downloads . getPreferredDownloadsDirectory ( ) ;
247- let filename = await OS . Path . join ( downloadsDir , targetFilename ) ;
246+ let filename = await PathUtils . join ( downloadsDir , targetFilename ) ;
248247 // need to nuke an existing file first.
249- if ( ( await OS . File . exists ( filename ) ) ) {
250- await OS . File . remove ( filename ) ;
248+ if ( ( await IOUtils . exists ( filename ) ) ) {
249+ await IOUtils . remove ( filename ) ;
251250 }
252251 let download = await Downloads . createDownload ( {
253252 source : sourceFileURI ,
@@ -287,14 +286,17 @@ class LogFilesComponent extends React.Component {
287286 }
288287 } ) ;
289288
290- let tmpFileInfo = await OS . File . openUnique (
291- OS . Path . join ( OS . Constants . Path . tmpDir , "aboutsync-combined-log.txt" ) )
289+ let combinedFilePath = PathUtils . join ( PathUtils . tempDir , "aboutsync-combined-log.txt" ) ;
290+ // need to nuke an existing file first.
291+ if ( ( await IOUtils . exists ( combinedFilePath ) ) ) {
292+ await IOUtils . remove ( combinedFilePath ) ;
293+ }
292294
293295 try {
294296 let textEncoder = new TextEncoder ( ) ;
295297 // as in cstdio
296298 async function puts ( string ) {
297- return tmpFileInfo . file . write ( textEncoder . encode ( string + "\n" ) ) ;
299+ return await IOUtils . write ( combinedFilePath , textEncoder . encode ( string + "\n" ) , { mode : "appendOrCreate" } ) ;
298300 }
299301
300302 await puts ( `Processing ${ files . length } files` ) ;
@@ -308,7 +310,7 @@ class LogFilesComponent extends React.Component {
308310 total : files . length
309311 }
310312 } ) ;
311- let entireFile = await OS . File . read ( entry . path , { encoding : "UTF-8" } ) ;
313+ let entireFile = await IOUtils . readUTF8 ( entry . path ) ;
312314 let entireFileLines = entireFile . split ( "\n" ) ;
313315
314316 if ( entireFileLines . length == 0 ) {
@@ -336,8 +338,8 @@ class LogFilesComponent extends React.Component {
336338 }
337339 await puts ( outLines . join ( "\n" ) ) ;
338340 }
339- } finally {
340- await tmpFileInfo . file . close ( ) ;
341+ } catch ( err ) {
342+ console . error ( "Error combining logs: " , err ) ;
341343 }
342344 this . setState ( {
343345 downloadingCombined : {
@@ -346,7 +348,7 @@ class LogFilesComponent extends React.Component {
346348 }
347349 } ) ;
348350
349- await this . downloadFile ( OS . Path . toFileURI ( tmpFileInfo . path ) , "aboutsync-combined-log.txt" ) ;
351+ await this . downloadFile ( PathUtils . toFileURI ( combinedFilePath ) , "aboutsync-combined-log.txt" ) ;
350352 }
351353
352354 async downloadCombined ( event ) {
@@ -369,23 +371,27 @@ class LogFilesComponent extends React.Component {
369371 } ) ;
370372 }
371373
372- componentDidMount ( ) {
374+ async componentDidMount ( ) {
373375 // find all our log-files.
374376 let logDir = FileUtils . getDir ( "ProfD" , [ "weave" , "logs" ] ) ;
375- let iterator = new OS . File . DirectoryIterator ( logDir . path ) ;
376-
377377 let result = {
378378 entries : [ ] ,
379379 numErrors : 0 ,
380380 }
381- iterator . forEach ( entry => {
382- result . entries . push ( entry ) ;
383- result . numErrors += entry . name . startsWith ( "error-" ) ? 1 : 0 ;
384- } ) . then ( ( ) => {
385- this . setState ( { logFiles : result } ) ;
386- } ) . catch ( err => {
381+ try {
382+ let iterator = await IOUtils . getChildren ( logDir . path ) ;
383+ iterator . forEach ( entry => {
384+ // IOUtils gives us the absolute path, but LOG_FILE_RE
385+ // and other operations operate on the filename
386+ let fileName = / [ ^ / ] * $ / . exec ( entry ) [ 0 ] ;
387+ result . entries . push ( { name : fileName , path : entry } ) ;
388+ result . numErrors += fileName . startsWith ( "error-" ) ? 1 : 0 ;
389+ } ) ;
390+ } catch ( err ) {
387391 console . error ( "Failed to fetch the logfiles" , err ) ;
388- } ) ;
392+ }
393+ // Update the state
394+ this . setState ( { logFiles : result } ) ;
389395 }
390396
391397 _processing ( kind , { current, total} ) {
0 commit comments