@ -184,7 +184,8 @@ export class HostedStorageManager implements IDocStorageManager {
* /
public async addToStorage ( docId : string ) {
if ( this . _disableS3 ) { return ; }
await this . _ext . upload ( docId , this . getPath ( docId ) ) ;
this . _uploads . addOperation ( docId ) ;
await this . _uploads . expediteOperationAndWait ( docId ) ;
}
public getPath ( docName : string ) : string {
@ -234,6 +235,13 @@ export class HostedStorageManager implements IDocStorageManager {
}
}
public async prepareToCreateDoc ( docName : string ) : Promise < void > {
if ( this . _inventory ) {
await this . _inventory . create ( docName ) ;
this . _onInventoryChange ( docName ) ;
}
}
// Gets a copy of the document, eg. for downloading. Returns full file path.
// Copy won't change if edits are made to the document. It is caller's responsibility
// to delete the result.
@ -656,10 +664,7 @@ export class HostedStorageManager implements IDocStorageManager {
metadata
}
await this . _inventory . add ( docId , snapshot , prevSnapshotId ) ;
const scheduled = this . _pruner . requestPrune ( docId ) ;
if ( ! scheduled ) {
await this . _inventory . flush ( docId ) ;
}
await this . _onInventoryChange ( docId ) ;
} finally {
// Clean up backup.
// NOTE: fse.remove succeeds also when the file does not exist.
@ -667,6 +672,14 @@ export class HostedStorageManager implements IDocStorageManager {
}
}
// Make sure inventory change is followed up on.
private async _onInventoryChange ( docId : string ) {
const scheduled = this . _pruner . requestPrune ( docId ) ;
if ( ! scheduled ) {
await this . _inventory . flush ( docId ) ;
}
}
// Extract actionHash, actionNum, and timezone from a document backup.
private async _getDocMetadata ( fname : string ) : Promise < { [ key : string ] : string } > {
const result : Record < string , string > = { } ;