This is an automated email from the ASF dual-hosted git repository. pdallig pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/zeppelin.git
The following commit(s) were added to refs/heads/master by this push: new ad18bc099d [ZEPPELIN-6051] Skip the hidden files in notebook listing (reopen) (#4792) ad18bc099d is described below commit ad18bc099d7d8006e5b6b350c13a462a2b967eb9 Author: SeungYoung Oh <seung...@naver.com> AuthorDate: Thu Aug 15 15:19:20 2024 +0900 [ZEPPELIN-6051] Skip the hidden files in notebook listing (reopen) (#4792) * feat: Skip listing of invalid file names * test: Remove an unnecessary field from VFSNotebookRepoTest * feat: Enhance parsing error messages * feat: Add newline processing in error popups Convert "\n" (newline characters) to HTML line breaks in error popups messages. * refactor: Fix typo in method name * Revert "feat: Add newline processing in error popups" This reverts commit ab4b99b97ad3ed8f91ec11a7ce7c085f5751bad7. * feat: Remove newlines and modify error messages when parsing notebooks --- .../zeppelin/notebook/repo/VFSNotebookRepo.java | 30 ++++++++++++----- .../notebook/repo/VFSNotebookRepoTest.java | 38 ++++++++++++++++++---- 2 files changed, 53 insertions(+), 15 deletions(-) diff --git a/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/repo/VFSNotebookRepo.java b/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/repo/VFSNotebookRepo.java index 74607da3a1..70175f5538 100644 --- a/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/repo/VFSNotebookRepo.java +++ b/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/repo/VFSNotebookRepo.java @@ -39,6 +39,7 @@ import org.apache.zeppelin.conf.ZeppelinConfiguration.ConfVars; import org.apache.zeppelin.notebook.Note; import org.apache.zeppelin.notebook.NoteInfo; import org.apache.zeppelin.notebook.NoteParser; +import org.apache.zeppelin.notebook.exception.CorruptedNoteException; import org.apache.zeppelin.user.AuthenticationInfo; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -102,11 +103,13 @@ public class VFSNotebookRepo extends AbstractNotebookRepo { private Map<String, NoteInfo> listFolder(FileObject fileObject) throws IOException { Map<String, NoteInfo> noteInfos = new HashMap<>(); + + if (fileObject.getName().getBaseName().startsWith(".")) { + LOGGER.warn("Skip hidden item: {}", fileObject.getName()); + return noteInfos; + } + if (fileObject.isFolder()) { - if (fileObject.getName().getBaseName().startsWith(".")) { - LOGGER.warn("Skip hidden folder: {}", fileObject.getName().getPath()); - return noteInfos; - } for (FileObject child : fileObject.getChildren()) { noteInfos.putAll(listFolder(child)); } @@ -134,10 +137,21 @@ public class VFSNotebookRepo extends AbstractNotebookRepo { NameScope.DESCENDENT); String json = IOUtils.toString(noteFile.getContent().getInputStream(), zConf.getString(ConfVars.ZEPPELIN_ENCODING)); - Note note = noteParser.fromJson(noteId, json); - // setPath here just for testing, because actually NoteManager will setPath - note.setPath(notePath); - return note; + + try { + Note note = noteParser.fromJson(noteId, json); + // setPath here just for testing, because actually NoteManager will setPath + note.setPath(notePath); + return note; + } catch (CorruptedNoteException e) { + String errorMessage = String.format( + "Fail to parse note json. Please check the file at this path to resolve the issue. " + + "Path: %s, " + + "Content: %s", + rootNotebookFolder + notePath, json + ); + throw new CorruptedNoteException(noteId, errorMessage, e); + } } @Override diff --git a/zeppelin-zengine/src/test/java/org/apache/zeppelin/notebook/repo/VFSNotebookRepoTest.java b/zeppelin-zengine/src/test/java/org/apache/zeppelin/notebook/repo/VFSNotebookRepoTest.java index c69d1dbed5..9bf02c0b3d 100644 --- a/zeppelin-zengine/src/test/java/org/apache/zeppelin/notebook/repo/VFSNotebookRepoTest.java +++ b/zeppelin-zengine/src/test/java/org/apache/zeppelin/notebook/repo/VFSNotebookRepoTest.java @@ -45,22 +45,21 @@ class VFSNotebookRepoTest { private ZeppelinConfiguration zConf; private NoteParser noteParser; private VFSNotebookRepo notebookRepo; - private File notebookDir; @BeforeEach public void setUp() throws IOException { + File notebookDir = Files.createTempDirectory(this.getClass().getSimpleName()).toFile(); zConf = ZeppelinConfiguration.load(); noteParser = new GsonNoteParser(zConf); - notebookDir = Files.createTempDirectory(this.getClass().getSimpleName()).toFile(); - zConf.setProperty(ZeppelinConfiguration.ConfVars.ZEPPELIN_NOTEBOOK_DIR.getVarName(), - notebookDir.getAbsolutePath()); + zConf.setProperty(ZeppelinConfiguration.ConfVars.ZEPPELIN_NOTEBOOK_DIR.getVarName(), notebookDir.getAbsolutePath()); notebookRepo = new VFSNotebookRepo(); notebookRepo.init(zConf, noteParser); } @AfterEach public void tearDown() throws IOException { - FileUtils.deleteDirectory(notebookDir); + File rootDir = new File(notebookRepo.rootNotebookFolder); + FileUtils.deleteDirectory(rootDir); } @Test @@ -137,7 +136,7 @@ class VFSNotebookRepoTest { assertEquals(1, repoSettings.size()); NotebookRepoSettingsInfo settingInfo = repoSettings.get(0); assertEquals("Notebook Path", settingInfo.name); - assertEquals(notebookDir.getAbsolutePath(), settingInfo.selected); + assertEquals(notebookRepo.rootNotebookFolder, settingInfo.selected); createNewNote("{}", "id2", "my_project/name2"); assertEquals(1, notebookRepo.list(AuthenticationInfo.ANONYMOUS).size()); @@ -149,8 +148,33 @@ class VFSNotebookRepoTest { assertEquals(0, notebookRepo.list(AuthenticationInfo.ANONYMOUS).size()); } + @Test + void testSkipInvalidFileName() throws IOException { + assertEquals(0, notebookRepo.list(AuthenticationInfo.ANONYMOUS).size()); + + createNewNote("{}", "hidden_note", "my_project/.hidden_note"); + + Map<String, NoteInfo> noteInfos = notebookRepo.list(AuthenticationInfo.ANONYMOUS); + assertEquals(0, noteInfos.size()); + } + + @Test + void testSkipInvalidDirectoryName() throws IOException { + createNewDirectory(".hidden_dir"); + + createNewNote("{}", "hidden_note", "my_project/.hidden_dir/note"); + + Map<String, NoteInfo> noteInfos = notebookRepo.list(AuthenticationInfo.ANONYMOUS); + assertEquals(0, noteInfos.size()); + } + private void createNewNote(String content, String noteId, String noteName) throws IOException { FileUtils.writeStringToFile( - new File(notebookDir + "/" + noteName + "_" + noteId + ".zpln"), content, StandardCharsets.UTF_8); + new File(notebookRepo.rootNotebookFolder + "/" + noteName + "_" + noteId + ".zpln"), content, StandardCharsets.UTF_8); + } + + private void createNewDirectory(String dirName) { + File dir = new File(notebookRepo.rootNotebookFolder + "/" + dirName); + dir.mkdir(); } }