From fa554d7619c80de0184366f51ba927037959c2d5 Mon Sep 17 00:00:00 2001 From: thindil <> Date: Mon, 9 May 2022 04:57:39 +0000 Subject: [PATCH] feat: skip setting environment variables when their current value is the same as was FossilOrigin-Name: 0253dcb4e2b83f56c4b2c5b5f333860f09fbcb36bbe8814a25ab6c4a32ac6e96 --- src/variables.nim | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/variables.nim b/src/variables.nim index dc06c054..92df8e9b 100644 --- a/src/variables.nim +++ b/src/variables.nim @@ -84,22 +84,29 @@ proc setVariables*(newDirectory: DirectoryPath; db; ## * oldDirectory - the old directory in which environment variables will be ## removed. Can be empty. Default value is empty + var skipped: seq[string] + # Remove the old environment variables if needed if oldDirectory.len() > 0: try: for dbResult in db.fastRows(query = sql(query = buildQuery( directory = oldDirectory, fields = "name, value"))): - if db.getRow(query = sql(query = buildQuery(directory = newDirectory, - fields = "id", where = "AND name='" & dbResult[0] & - "' AND value='" & dbResult[1] & "'"))) == @[]: + let existingVariable: Row = db.getRow(query = sql(query = buildQuery( + directory = newDirectory, fields = "id", where = "AND name='" & + dbResult[0] & "' AND value='" & dbResult[1] & "'"))) + if existingVariable.len() == 0: delEnv(key = dbResult[0]) + else: + skipped.add(y = existingVariable[0]) except DbError, OSError: discard showError(message = "Can't delete environment variables from the old directory. Reason: " & getCurrentExceptionMsg()) # Set the new environment variables try: for dbResult in db.fastRows(query = sql(query = buildQuery( - directory = newDirectory, fields = "name, value"))): + directory = newDirectory, fields = "name, value, id"))): + if dbResult[2] in skipped: + continue var value: string = dbResult[1] variableIndex: ExtendedNatural = value.find(sub = '$')