From 4f1eee48cc04db83aae1930ea421d757e9208194 Mon Sep 17 00:00:00 2001 From: Nayan Date: Thu, 21 Sep 2023 07:04:29 +0600 Subject: [PATCH] fix: Git import fails when pages directory contains a file (#27467) ## Description It fixes the Git import failure bug when there's a file in the pages directory. #### PR fixes following issue(s) Fixes #27466 --- .../appsmith/git/helpers/FileUtilsImpl.java | 37 ++++++++++--------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/app/server/appsmith-git/src/main/java/com/appsmith/git/helpers/FileUtilsImpl.java b/app/server/appsmith-git/src/main/java/com/appsmith/git/helpers/FileUtilsImpl.java index 66dcdad5c3..c4321e15f8 100644 --- a/app/server/appsmith-git/src/main/java/com/appsmith/git/helpers/FileUtilsImpl.java +++ b/app/server/appsmith-git/src/main/java/com/appsmith/git/helpers/FileUtilsImpl.java @@ -960,25 +960,28 @@ public class FileUtilsImpl implements FileInterface { // Loop through all the directories and nested directories inside the pages directory to extract // pages, actions and actionCollections from the JSON files for (File page : Objects.requireNonNull(directory.listFiles())) { - pageMap.put(page.getName(), readPageMetadata(page.toPath(), gson)); + if (page.isDirectory()) { + pageMap.put(page.getName(), readPageMetadata(page.toPath(), gson)); - JSONObject mainContainer = getMainContainer(pageMap.get(page.getName()), gson); + JSONObject mainContainer = getMainContainer(pageMap.get(page.getName()), gson); - // Read widgets data recursively from the widgets directory - Map widgetsData = readWidgetsData( - page.toPath().resolve(CommonConstants.WIDGETS).toString()); - // Construct the nested DSL from the widgets data - Map> parentDirectories = DSLTransformerHelper.calculateParentDirectories( - widgetsData.keySet().stream().toList()); - JSONObject nestedDSL = DSLTransformerHelper.getNestedDSL(widgetsData, parentDirectories, mainContainer); - pageDsl.put(page.getName(), nestedDSL.toString()); - actionMap.putAll( - readAction(page.toPath().resolve(ACTION_DIRECTORY), gson, page.getName(), actionBodyMap)); - actionCollectionMap.putAll(readActionCollection( - page.toPath().resolve(ACTION_COLLECTION_DIRECTORY), - gson, - page.getName(), - actionCollectionBodyMap)); + // Read widgets data recursively from the widgets directory + Map widgetsData = readWidgetsData( + page.toPath().resolve(CommonConstants.WIDGETS).toString()); + // Construct the nested DSL from the widgets data + Map> parentDirectories = DSLTransformerHelper.calculateParentDirectories( + widgetsData.keySet().stream().toList()); + JSONObject nestedDSL = + DSLTransformerHelper.getNestedDSL(widgetsData, parentDirectories, mainContainer); + pageDsl.put(page.getName(), nestedDSL.toString()); + actionMap.putAll( + readAction(page.toPath().resolve(ACTION_DIRECTORY), gson, page.getName(), actionBodyMap)); + actionCollectionMap.putAll(readActionCollection( + page.toPath().resolve(ACTION_COLLECTION_DIRECTORY), + gson, + page.getName(), + actionCollectionBodyMap)); + } } } applicationGitReference.setActions(actionMap);