From 8db2c3d8211751f166b21731e05b0d97456879a8 Mon Sep 17 00:00:00 2001 From: winlin Date: Mon, 16 Mar 2020 11:39:20 +0800 Subject: [PATCH] For #1635, refine inotify watch for relative path --- trunk/src/kernel/srs_kernel_utility.cpp | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/trunk/src/kernel/srs_kernel_utility.cpp b/trunk/src/kernel/srs_kernel_utility.cpp index 861be3610..5fe03a129 100644 --- a/trunk/src/kernel/srs_kernel_utility.cpp +++ b/trunk/src/kernel/srs_kernel_utility.cpp @@ -652,15 +652,20 @@ bool srs_path_exists(std::string path) string srs_path_dirname(string path) { std::string dirname = path; + + // No slash, it must be current dir. size_t pos = string::npos; - - if ((pos = dirname.rfind("/")) != string::npos) { - if (pos == 0) { - return "/"; - } - dirname = dirname.substr(0, pos); + if ((pos = dirname.rfind("/")) == string::npos) { + return "./"; } - + + // Path under root. + if (pos == 0) { + return "/"; + } + + // Fetch the directory. + dirname = dirname.substr(0, pos); return dirname; }