From a3fef0d80eaed16f43c7d472bbcbf6e2bbfae34f Mon Sep 17 00:00:00 2001 From: Samuel Albrecht Date: Sat, 28 Jan 2023 15:09:21 +0100 Subject: [PATCH] fix: win: compile linuxtuils only on linux --- src/linuxutils.cpp | 37 ++++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/src/linuxutils.cpp b/src/linuxutils.cpp index 51456c2..972dda7 100644 --- a/src/linuxutils.cpp +++ b/src/linuxutils.cpp @@ -1,4 +1,5 @@ #include "linuxutils.hpp" +#if BOOST_OS_LINUX #include "boost/process/child.hpp" #include "boost/process/search_path.hpp" @@ -16,23 +17,23 @@ namespace bp = boost::process; //! return dir of snap program //! \arg browser, e.g. "firefox" //! \returns snap dir, e.g. "~/snap/firefox" -fs::path snapDir(const std::string& browser) { - const char* home = getenv("HOME"); +fs::path snapDir( const std::string& browser ) { + const char* home = getenv( "HOME" ); - if(!home) { return {}; } + if( !home ) { return {}; } - return fs::path(home) / "snap" / browser; + return fs::path( home ) / "snap" / browser; } //! return default program for mimetype //! \arg mime e.g. "text/html" //! \returns program, e.g. "firefox.desktop" -std::string queryOpen(const std::string& mime) { +std::string queryOpen( const std::string& mime ) { bp::ipstream out; std::vector outline; - bp::child nm(bp::search_path("xdg-mime"), bp::args({"query", "default", mime}), bp::std_out > out); + bp::child nm( bp::search_path( "xdg-mime" ), bp::args( {"query", "default", mime} ), bp::std_out > out ); std::string value; out >> value; @@ -41,29 +42,31 @@ std::string queryOpen(const std::string& mime) { } //! check if browser is a snap browser -bool defaultBrowserIsSnap(const std::string& browser) { +bool defaultBrowserIsSnap( const std::string& browser ) { - fs::path snap = snapDir(browser); + fs::path snap = snapDir( browser ); - if(snap.empty()) { return false; } + if( snap.empty() ) { return false; } - if(!fs::exists(snap)) { return false; } + if( !fs::exists( snap ) ) { return false; } - std::string program = queryOpen("text/html"); + std::string program = queryOpen( "text/html" ); return program == browser + ".desktop"; } -fs::path copyToSnapDir(const boost::filesystem::path& orig) { +fs::path copyToSnapDir( const boost::filesystem::path& orig ) { - for(auto&& browser : {"firefox", "chromium" }) { - if(defaultBrowserIsSnap(browser)) { - fs::path newDir = snapDir(browser) / "fsrc"; + for( auto&& browser : {"firefox", "chromium" } ) { + if( defaultBrowserIsSnap( browser ) ) { + fs::path newDir = snapDir( browser ) / "fsrc"; fs::path copy = newDir / orig.filename(); - fs::create_directories(newDir); - fs::copy(orig, copy, fs::copy_options::overwrite_existing); + fs::create_directories( newDir ); + fs::copy( orig, copy, fs::copy_options::overwrite_existing ); return copy; } } return orig; } + +#endif // BOOST_OS_LINUX