Skip to content

Commit c7a6d01

Browse files
authored
Merge pull request #4584 from bruntib/sqlite_in_workspace_dir
[fix] Emit error message when SQLite DB is not under workspace dir
2 parents c22ad89 + 1a504db commit c7a6d01

3 files changed

Lines changed: 37 additions & 2 deletions

File tree

web/server/codechecker_server/api/product_server.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,11 @@ def addProduct(self, product):
418418
# SQLite-backed product in a different directory, we follow
419419
# symlinks, but not when storing the path.
420420
if dbc.engine == 'sqlite':
421+
if os.path.isabs(dbc.database):
422+
raise codechecker_api_shared.ttypes.RequestFailed(
423+
codechecker_api_shared.ttypes.ErrorCode.DATABASE,
424+
"SQLite database must be given by relative path!")
425+
421426
dbc.database = path_for_fake_root(os.path.join("/", dbc.database),
422427
self.__server.config_directory)
423428

@@ -493,6 +498,16 @@ def addProduct(self, product):
493498
# Connect and create the database schema.
494499
self.__server.add_product(orm_prod, init_db=True)
495500
connection_wrapper = self.__server.get_product(product.endpoint)
501+
502+
if connection_wrapper is None:
503+
err_msg = "Failed to add product."
504+
if dbc.engine == 'sqlite':
505+
err_msg += " The SQLite database file must be under the " \
506+
"server workspace directory."
507+
raise codechecker_api_shared.ttypes.RequestFailed(
508+
codechecker_api_shared.ttypes.ErrorCode.DATABASE,
509+
err_msg)
510+
496511
if connection_wrapper.last_connection_failure:
497512
msg = \
498513
f"The configured connection for '/{product.endpoint}' " \
@@ -584,6 +599,10 @@ def editProduct(self, product_id, new_config):
584599

585600
old_args = SQLServer.connection_string_to_args(product.connection)
586601
if dbc.engine == 'sqlite' and dbc.database != old_args['sqlite']:
602+
if os.path.isabs(dbc.database):
603+
raise codechecker_api_shared.ttypes.RequestFailed(
604+
codechecker_api_shared.ttypes.ErrorCode.DATABASE,
605+
"SQLite database must be given by relative path!")
587606
dbc.database = path_for_fake_root(
588607
os.path.join("/", dbc.database),
589608
self.__server.config_directory)
@@ -667,6 +686,17 @@ def editProduct(self, product_id, new_config):
667686
LOG.debug("Product database successfully connected to.")
668687

669688
connection_wrapper = self.__server.get_product(dummy_endpoint)
689+
690+
if connection_wrapper is None:
691+
err_msg = "Failed to edit product."
692+
if dbc.engine == 'sqlite':
693+
err_msg += " The SQLite database file must be under " \
694+
"the server workspace directory."
695+
696+
raise codechecker_api_shared.ttypes.RequestFailed(
697+
codechecker_api_shared.ttypes.ErrorCode.DATABASE,
698+
err_msg)
699+
670700
if connection_wrapper.last_connection_failure:
671701
msg = \
672702
f"The configured connection for " \

web/server/codechecker_server/server.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -934,6 +934,13 @@ def add_product(self, orm_product, init_db=False):
934934

935935
# Update the product database status.
936936
prod.connect()
937+
938+
if prod.db_status == DBStatus.FAILED_TO_CONNECT:
939+
LOG.debug(
940+
"Failed to connect to database for product '%s'",
941+
orm_product.endpoint)
942+
return
943+
937944
if prod.db_status == DBStatus.SCHEMA_MISSING and init_db:
938945
LOG.debug("Schema was missing in the database. Initializing new")
939946
prod.connect(init_db=True)

web/server/vue-cli/src/components/Product/EditProductBtn.vue

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,6 @@ export default {
147147
this.success = true;
148148
this.$emit("on-complete",
149149
new ProductConfiguration(this.productConfig));
150-
}, () => {
151-
this.error = true;
152150
}));
153151
154152
// Save permissions.

0 commit comments

Comments
 (0)