File: absdest

package info (click to toggle)
icmake 13.05.01-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 7,132 kB
  • sloc: cpp: 11,595; fortran: 883; makefile: 853; sh: 546; pascal: 342
file content (25 lines) | stat: -rw-r--r-- 1,108 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
    // destination entries can be copied from the
    // source entries (files or directories) 
    // if they start with ~/ or / then that part is removed.
    //
    // g_destPath is prefixed to the destination and its absolute path is
    // determined: the resulting destination must start with destPath as
    // it must be below destpath. 
string absDest(string dest)
{
    int offset =                        // offset of the actual dest-entry:
        strfind(dest, "~/") == 0 ?  2 :         // relative to HOME
        strfind(dest, "/")  == 0 ?  1 :         // absolute
                                    0;          // as-is
    if (offset != 0)               
        dest = substr(dest, offset, 999);       // remove the prefix

    dest = readlink(g_destPath + dest);         // convert to abs. path

                                                // the new 'dest' must
                                                // now begin with g_destPath:
    if (strfind(dest, g_destPath) != 0)
        quit("dest: `" + dest + "' doesn't start with  `" + g_destPath + "'");
    
    return dest;
}