MCPcopy Create free account
hub / github.com/aboutcode-org/scancode-workbench / _addFiles

Method _addFiles

src/services/workbenchDB.ts:985–1085  ·  view source on GitHub ↗
(files: Resource[])

Source from the content-addressed store, hash-verified

983 }
984
985 _addFiles(files: Resource[]) {
986 const transactionOptions: TransactionOptions = {
987 autocommit: false,
988 isolationLevel: Transaction.ISOLATION_LEVELS.READ_COMMITTED,
989 };
990 return this.sequelize.transaction(transactionOptions, (t) => {
991 const options: BulkCreateOptions = {
992 // logging: () => DebugLogger("add file", "AddFiles transaction executed !"),
993 transaction: t,
994 };
995 files.forEach((file) => {
996 // Fix for issue #232
997 if (
998 file.type === "directory" &&
999 Object.prototype.hasOwnProperty.call(file, "size_count")
1000 ) {
1001 file.size = file.size_count;
1002 }
1003 file.parent = parentPath(file.path);
1004 });
1005
1006 return this.db.File.bulkCreate(files, options)
1007 .then(() => DebugLogger("file processor", "Processed bulkcreate"))
1008
1009 .then(() =>
1010 this.db.LicenseExpression.bulkCreate(
1011 this._getLicenseExpressions(files),
1012 options
1013 )
1014 )
1015 .then(() =>
1016 DebugLogger("license exp processor", "Processed license_exp")
1017 )
1018
1019 .then(() =>
1020 this.db.LicensePolicy.bulkCreate(
1021 this._addExtraFields(files, "license_policy"),
1022 options
1023 )
1024 )
1025 .then(() =>
1026 DebugLogger("license policy processor", "Processed license_policy")
1027 )
1028
1029 .then(() =>
1030 this.db.Copyright.bulkCreate(
1031 this._addExtraFields(files, "copyrights"),
1032 options
1033 )
1034 )
1035 .then(() => DebugLogger("copyright processor", "Processed copyrights"))
1036
1037 .then(() =>
1038 this.db.PackageData.bulkCreate(
1039 this._addExtraFields(files, "package_data"),
1040 options
1041 )
1042 )

Callers 1

_batchCreateFilesMethod · 0.95

Calls 5

_addExtraFieldsMethod · 0.95
parentPathFunction · 0.90
DebugLoggerFunction · 0.90
logDependenciesOnErrorFunction · 0.90

Tested by

no test coverage detected