From ce73e2bebdc39646d56c33e8f5185acc52ccdeda Mon Sep 17 00:00:00 2001 From: allan Date: Fri, 6 Jun 2025 20:29:07 +0100 Subject: [PATCH] feat: new mfv_getfolderpath macro + associated test created to support the fix for https://git.datacontroller.io/dc/dc/issues/171 --- tests/viyaonly/mfv_getfolderpath.test.sas | 31 +++++++++++++ tests/viyaonly/mfv_getpathuri.test.sas | 2 +- viya/mfv_getfolderpath.sas | 53 +++++++++++++++++++++++ 3 files changed, 85 insertions(+), 1 deletion(-) create mode 100644 tests/viyaonly/mfv_getfolderpath.test.sas create mode 100644 viya/mfv_getfolderpath.sas diff --git a/tests/viyaonly/mfv_getfolderpath.test.sas b/tests/viyaonly/mfv_getfolderpath.test.sas new file mode 100644 index 0000000..661e4b4 --- /dev/null +++ b/tests/viyaonly/mfv_getfolderpath.test.sas @@ -0,0 +1,31 @@ +/** + @file + @brief Testing mfv_getfolderpath macro function + +

SAS Macros

+ @li mf_uid.sas + @li mfv_getfolderpath.sas + @li mfv_getpathuri.sas + @li mp_assert.sas + @li mv_createfolder.sas + +**/ + +options mprint sgen; + +%let folder=%mf_uid(); +/* create a folder */ +%mv_createfolder(path=&mcTestAppLoc/&folder) +%mp_assert( + iftrue=(&syscc=0), + desc=no errs on folder creation +) + +%let uri=%mfv_getpathuri(&mcTestAppLoc/&folder); +%put %mfv_getfolderpath(&uri); + +%mp_assert( + iftrue=("%mfv_getfolderpath(&uri)"="&mcTestAppLoc/&folder"), + desc=Check if correct folder was returned +) + diff --git a/tests/viyaonly/mfv_getpathuri.test.sas b/tests/viyaonly/mfv_getpathuri.test.sas index ef3a866..eb8b0a6 100644 --- a/tests/viyaonly/mfv_getpathuri.test.sas +++ b/tests/viyaonly/mfv_getpathuri.test.sas @@ -14,7 +14,7 @@ options mprint sgen; %let file=%mf_uid(); -/* create a folder */ +/* create a file */ filename somefile temp; data _null_; file somefile; diff --git a/viya/mfv_getfolderpath.sas b/viya/mfv_getfolderpath.sas new file mode 100644 index 0000000..159c0ba --- /dev/null +++ b/viya/mfv_getfolderpath.sas @@ -0,0 +1,53 @@ +/** + @file + @brief Returns the path of a folder from the URI + @details Makes use of the SYSMSG() ER8OR response, which resolves the uri, + seemingly without entering an er8or state. + + Usage: + + %mv_createfolder(path=/public/demo) + %let uri=%mfv_getpathuri(/public/demo); + %put %mfv_getfolderpath(&uri); + + Notice above the new path has an uppercase P - the correct path. + + @param [in] uri The uri of the folder -eg /folders/folders/xxxx) + +

SAS Macros

+ @li mf_getuniquefileref.sas + +

Related Macros

+ @li mfv_getpathuri.sas + + @version 4 + @author [Allan Bowe](https://www.linkedin.com/in/allanbowe/) +**/ +%macro mfv_getfolderpath(uri +)/*/STORE SOURCE*/; + + %local fref rc path msg var /* var used to avoid delete timing issue */; + %let fref=%mf_getuniquefileref(); + %if %quote(%substr(%str(&uri),1,17)) ne %quote(/folders/folders/) + %then %do; + %put &sysmacroname: Invalid URI: &uri; + %end; + %else %if %sysfunc(filename(fref,,filesrvc,folderuri="&uri" ))=0 + %then %do; + %let var=_FILESRVC_&fref._URI; + %local fid ; + %let fid= %sysfunc(fopen(&fref,I)); + %let msg=%quote(%sysfunc(sysmsg())); + + %unquote(%scan(&msg,2,%str(,.))) + + %let rc=%sysfunc(fclose(&fid)); + %let rc=%sysfunc(filename(fref)); + %symdel &var; + %end; + %else %do; + %put &sysmacroname: Not Found: &uri; + %let syscc=0; + %end; + +%mend mfv_getfolderpath ; \ No newline at end of file