@@ -25,56 +25,26 @@ export class BricksSyncParser {
2525 // const s1 = "Action: PUT: g, .gitignore, DELETE: f"
2626 // A hacky way to solve this, lets move to structed logs from bricks later
2727 private parseForActionsInitiated ( line : string ) {
28- const indexOfAction = line . indexOf ( "Action:" ) ;
29- // The log line is not relevant for actions
30- if ( indexOfAction === - 1 ) {
28+ const match = line . match ( / A c t i o n : ( P U T : ( .* ?) ) ? ( D E L E T E : ( .* ?) ) ? $ / ) ;
29+ if ( ! match ) {
3130 return ;
3231 }
3332
34- const tokenizedLine = line . substring ( indexOfAction ) . split ( " " ) ;
35- let isPut = false ;
36- let isDelete = false ;
37- for ( let i = 1 ; i < tokenizedLine . length ; i ++ ) {
38- switch ( tokenizedLine [ i ] ) {
39- case "PUT:" : {
40- isPut = true ;
41- isDelete = false ;
42- break ;
43- }
44- case "DELETE:" : {
45- isDelete = true ;
46- isPut = false ;
47- break ;
48- }
49- default : {
50- // trim the trailing , if it exists
51- const filePath = tokenizedLine [ i ] . replace ( / , $ / , "" ) ;
52- if ( isPut ) {
53- this . filesBeingUploaded . add ( filePath ) ;
54- } else if ( isDelete ) {
55- this . filesBeingDeleted . add ( filePath ) ;
56- } else {
57- throw new Error (
58- "[BricksSyncParser] unexpected logs recieved"
59- ) ;
60- }
61- }
62- }
63- }
33+ const toAdd = match [ 2 ] ?. split ( ", " ) ;
34+ const toDelete = match [ 4 ] ?. split ( ", " ) ;
35+
36+ toAdd ?. forEach ( ( f ) => this . filesBeingUploaded . add ( f ) ) ;
37+ toDelete ?. forEach ( ( f ) => this . filesBeingDeleted . add ( f ) ) ;
6438 }
6539
6640 // We expect a single line of logs for all files being put/delete
6741 private parseForUploadCompleted ( line : string ) {
68- const indexOfUploaded = line . indexOf ( " Uploaded" ) ;
69- if ( indexOfUploaded === - 1 ) {
42+ const match = line . match ( / U p l o a d e d ( . * ) / ) ;
43+ if ( ! match ) {
7044 return ;
7145 }
7246
73- const tokenizedLine = line . substring ( indexOfUploaded ) . split ( " " ) ;
74- if ( tokenizedLine . length !== 2 ) {
75- throw new Error ( "[BricksSyncParser] unexpected logs recieved" ) ;
76- }
77- const filePath = tokenizedLine [ 1 ] ;
47+ const filePath = match [ 1 ] ;
7848 if ( ! this . filesBeingUploaded . has ( filePath ) ) {
7949 throw new Error (
8050 "[BricksSyncParser] untracked file uploaded. All upload complete " +
@@ -89,16 +59,12 @@ export class BricksSyncParser {
8959 }
9060
9161 private parseForDeleteCompleted ( line : string ) {
92- const indexOfDeleted = line . indexOf ( " Deleted" ) ;
93- if ( indexOfDeleted === - 1 ) {
62+ const match = line . match ( / D e l e t e d ( . * ) / ) ;
63+ if ( ! match ) {
9464 return ;
9565 }
9666
97- const tokenizedLine = line . substring ( indexOfDeleted ) . split ( " " ) ;
98- if ( tokenizedLine . length !== 2 ) {
99- throw new Error ( "[BricksSyncParser] unexpected logs recieved" ) ;
100- }
101- const filePath = tokenizedLine [ 1 ] ;
67+ const filePath = match [ 1 ] ;
10268 if ( ! this . filesBeingDeleted . has ( filePath ) ) {
10369 throw new Error (
10470 "[BricksSyncParser] untracked file deleted. All delete complete " +
0 commit comments