Zesstra | 0d64cca | 2020-03-09 21:03:56 +0100 | [diff] [blame] | 1 | #pragma strict_types, rtt_checks, range_check, no_clone |
Zesstra | ccc58df | 2018-11-07 23:25:20 +0100 | [diff] [blame] | 2 | |
| 3 | #include <config.h> |
| 4 | #include <shells.h> |
| 5 | #include <defines.h> |
| 6 | |
| 7 | // Ersetzt Platzhalter im Pfad und versorgt relative Pfade mit P_CURRENTDIR |
| 8 | // Funktionalitaet war mal im master() in der Rechtepruefung, gehoert da aber |
| 9 | // wirklich nicht hin. |
| 10 | string expand_path(string path, string user) |
| 11 | { |
| 12 | string cwd; |
| 13 | if (!sizeof(path)) |
| 14 | return path; |
| 15 | switch(path[0]) |
| 16 | { |
| 17 | // expand nur fuer nicht-absolute Pfade |
| 18 | case '/': |
| 19 | break; |
| 20 | case '+': |
| 21 | if(sizeof(path)==1) |
| 22 | path="/"DOMAINDIR; |
| 23 | path="/"DOMAINDIR"/" + path[1..]; |
| 24 | break; |
| 25 | case '~': |
| 26 | if (sizeof(path)==1) |
| 27 | { |
| 28 | if(user) |
| 29 | path="/"WIZARDDIR"/"+user; |
| 30 | else |
| 31 | path="/"WIZARDDIR; |
| 32 | } |
| 33 | else |
| 34 | { |
| 35 | if(user && sizeof(path)>1 && path[1]=='/') // "~/" |
| 36 | path="/"WIZARDDIR"/" + user + "/" + path[2..]; |
| 37 | else |
| 38 | path="/"WIZARDDIR"/" + path[1..]; |
| 39 | } |
| 40 | break; |
| 41 | default: |
| 42 | if(user && PL && getuid(PL) == user |
Vanion | 5065232 | 2020-03-10 21:13:25 +0100 | [diff] [blame] | 43 | && (cwd=({string})PL->QueryProp(P_CURRENTDIR))) |
Zesstra | ccc58df | 2018-11-07 23:25:20 +0100 | [diff] [blame] | 44 | path=cwd + "/" + path; |
| 45 | } |
| 46 | return path; |
| 47 | } |
| 48 | |
| 49 | // Besser benamste Version von _get_path() aus master(). |
| 50 | // Normalisiert den Pfad, expandiert Platzhalter auf Wunsch, benutzt ggf. RPL |
| 51 | // oder PL als User, wenn nicht angegeben. |
| 52 | varargs string normalize_path(string path, string user, int expand) { |
| 53 | if (!user && (RPL || PL)) |
| 54 | user = getuid(RPL || PL); |
| 55 | if (expand) |
| 56 | path=expand_path(path, user); |
| 57 | return implode(master()->path_array(path), "/"); |
| 58 | } |
| 59 | |