private async getBlobWithLeaseUpdated()

in src/blob/persistence/SqlBlobMetadataStore.ts [3338:3416]


  private async getBlobWithLeaseUpdated(
    account: string,
    container: string,
    blob: string,
    snapshot: string = "",
    context: Context,
    forceExist?: boolean,
    forceCommitted?: boolean,
    transaction?: Transaction
  ): Promise<BlobModel | undefined> {
    await this.checkContainerExist(context, account, container);

    const blobFindResult = await BlobsModel.findOne({
      where: {
        accountName: account,
        containerName: container,
        blobName: blob,
        snapshot
      },
      transaction
    });

    if (blobFindResult === null || blobFindResult === undefined) {
      if (forceExist === false) {
        return undefined;
      } else {
        throw StorageErrorFactory.getBlobNotFound(context.contextId);
      }
    }

    // Force exist if parameter forceExist is undefined or true
    const doc = this.convertDbModelToBlobModel(blobFindResult);
    if (forceExist === undefined || forceExist === true) {
      if (forceCommitted) {
        if (!doc || !(doc as BlobModel).isCommitted) {
          throw StorageErrorFactory.getBlobNotFound(context.contextId);
        }
      } else {
        if (!doc) {
          throw StorageErrorFactory.getBlobNotFound(context.contextId);
        }
      }
    } else {
      if (forceCommitted) {
        if (!doc || !(doc as BlobModel).isCommitted) {
          return undefined;
        }
      } else {
        if (!doc) {
          return undefined;
        }
      }
    }

    if (doc.properties) {
      doc.properties.contentMD5 = this.restoreUint8Array(
        doc.properties.contentMD5
      );
    }

    // Snapshot doesn't have lease
    if (snapshot !== undefined && snapshot !== "") {
      new BlobLeaseSyncer(doc).sync({
        leaseId: undefined,
        leaseExpireTime: undefined,
        leaseDurationSeconds: undefined,
        leaseBreakTime: undefined,
        leaseDurationType: undefined,
        leaseState: Models.LeaseStateType.Available, // TODO: Lease state & status should be undefined for snapshots
        leaseStatus: Models.LeaseStatusType.Unlocked // TODO: Lease state & status should be undefined for snapshots
      });
    } else {
      LeaseFactory.createLeaseState(new BlobLeaseAdapter(doc), context).sync(
        new BlobLeaseSyncer(doc)
      );
    }

    return doc;
  }