From a4df1eb10fff55efa387583e0b230e324743c8c0 Mon Sep 17 00:00:00 2001 From: Matthias Koefferlein Date: Sun, 29 Oct 2023 21:44:31 +0100 Subject: [PATCH] Some bug fixing --- src/lay/lay/laySaltGrain.cc | 4 ++++ src/lay/lay/laySaltParsedURL.cc | 7 +++++-- src/lay/unit_tests/laySaltParsedURLTests.cc | 9 +++++++++ src/tl/tl/tlGit.cc | 18 ++++++++++++------ 4 files changed, 30 insertions(+), 8 deletions(-) diff --git a/src/lay/lay/laySaltGrain.cc b/src/lay/lay/laySaltGrain.cc index e887066e7..cd54e841f 100644 --- a/src/lay/lay/laySaltGrain.cc +++ b/src/lay/lay/laySaltGrain.cc @@ -515,6 +515,10 @@ SaltGrain::stream_from_url (std::string &generic_url, double timeout, tl::InputH throw tl::Exception (tl::to_string (QObject::tr ("No download link available"))); } + if (tl::verbosity () >= 20) { + tl::info << tr ("Downloading package info from ") << generic_url; + } + lay::SaltParsedURL purl (generic_url); const std::string &url = purl.url (); diff --git a/src/lay/lay/laySaltParsedURL.cc b/src/lay/lay/laySaltParsedURL.cc index 11767b1b4..84e2c0850 100644 --- a/src/lay/lay/laySaltParsedURL.cc +++ b/src/lay/lay/laySaltParsedURL.cc @@ -39,7 +39,7 @@ parse_git_url (tl::Extractor &ex, std::string &url, std::string &branch, std::st ; } // server ("www.klayout.de") - while (! ex.at_end () && (*ex != '/' && *ex != '+')) { + while (! ex.at_end () && (*ex != '/' && *ex != '+' && *ex != '[')) { ++ex; } @@ -47,6 +47,7 @@ parse_git_url (tl::Extractor &ex, std::string &url, std::string &branch, std::st ++ex; + // next component const char *c1 = ex.get (); while (! ex.at_end () && (*ex != '/' && *ex != '+' && *ex != '[')) { ++ex; @@ -55,7 +56,7 @@ parse_git_url (tl::Extractor &ex, std::string &url, std::string &branch, std::st std::string comp (c1, c2 - c1); - if ((! ex.at_end () && *ex == '+') || comp.find (".git") == comp.size () - 4) { + if ((! ex.at_end () && (*ex == '+' || *ex == '[')) || comp.find (".git") == comp.size () - 4) { // subfolder starts here break; } @@ -68,6 +69,7 @@ parse_git_url (tl::Extractor &ex, std::string &url, std::string &branch, std::st return; } + // skip URL/subfolder separator if (*ex == '/') { while (! ex.at_end () && *ex == '/') { ++ex; @@ -76,6 +78,7 @@ parse_git_url (tl::Extractor &ex, std::string &url, std::string &branch, std::st ++ex; } + // subfolders { const char *c1 = ex.get (); while (! ex.at_end () && *ex != '[') { diff --git a/src/lay/unit_tests/laySaltParsedURLTests.cc b/src/lay/unit_tests/laySaltParsedURLTests.cc index 96e22e5b6..b4274b3fd 100644 --- a/src/lay/unit_tests/laySaltParsedURLTests.cc +++ b/src/lay/unit_tests/laySaltParsedURLTests.cc @@ -130,3 +130,12 @@ TEST (19_GitSVNEmulationTagWithSubFolder) EXPECT_EQ (purl.branch (), "refs/tags/1.9"); EXPECT_EQ (purl.subfolder (), "sub/folder"); } + +TEST (20_Example1) +{ + lay::SaltParsedURL purl ("git+https://github.com/my-user/test-core[refs/tags/v1.1.0]"); + EXPECT_EQ (purl.protocol () == lay::Git, true); + EXPECT_EQ (purl.url (), "https://github.com/my-user/test-core"); + EXPECT_EQ (purl.branch (), "refs/tags/v1.1.0"); + EXPECT_EQ (purl.subfolder (), ""); +} diff --git a/src/tl/tl/tlGit.cc b/src/tl/tl/tlGit.cc index eb2336b7f..d1e100cad 100644 --- a/src/tl/tl/tlGit.cc +++ b/src/tl/tl/tlGit.cc @@ -79,17 +79,23 @@ GitObject::GitObject (const std::string &local_path) if (local_path.empty ()) { // @@@ generic tempnam on Windows/Posix ... - char tmp[] = "git2klayoutXXXXXX"; - mkstemp (tmp); + char tmp[] = "/tmp/git2klayoutXXXXXX"; + if (mkdtemp (tmp) == NULL) { + throw tl::Exception (tl::to_string (tr ("Unable to create temporary folder: %s")), (const char *) tmp); + } m_local_path = tmp; m_is_temp = true; } - tl::mkpath (m_local_path); - // ensures the directory is clean - tl::rm_dir_recursive (m_local_path); // @@@ TODO: error handling? - tl::mkpath (m_local_path); + if (! m_is_temp) { + if (! tl::rm_dir_recursive (m_local_path)) { + throw tl::Exception (tl::to_string (tr ("Unable to clean local Git repo path: %s")), m_local_path); + } + if (! tl::mkpath (m_local_path)) { + throw tl::Exception (tl::to_string (tr ("Unable to regenerate local Git repo path: %s")), m_local_path); + } + } } GitObject::~GitObject ()