symlink - c++ - resolve all symbolic links defined in a file path -


short version

how resolved path path 1 of dirs symbolic link:

example:

say path = /x/y/d/f1 y symbolic link /a/b

so result of resolved file path be: /x/a/b/d/f1

long version

i'd write c++ function copy files dir1 dir2 (of course not actual issue reduction of bigger , more complex problem).

prior copy process i'd remove files in dir2 going copied dir1. have:

  • dir1 = /a/b/c/d
  • dir2 = /x/y/d/

assume have file 'f1' in dir1 , file 'f1' in dir2, process do:

  1. remove /x/y/d/f1
  2. copy /a/b/c/d/f1 /x/y/d/f1

my problem following:

say dir 'y' symbolic link /a/b/c/. when remove /x/y/d/f1, removing /a/b/c/d/f1. (my example may have holes in it, hopw idea)

i'd avoid this, meaning, when come remove /x/y/d/f1 want able know i'll removing /x/y/d/f1 , skip remove

i tried using posix readlink() function works when file 'f1' symbolic link not work when 1 of parent dirs symbolic link.

any ideas?

following link give answer.

http://ubuntuforums.org/showthread.php?t=1126617

you can use following code resolve symilnks:

char buf[512]; int count = readlink("/x/y/d", buf, sizeof(buf)); if (count >= 0) {     buf[count] = '\0';     printf("%s -> %s\n", argv[1], buf); } 

in above code "d" path component should symlink. have iterate , resolve each path component.


Comments

Popular posts from this blog

java - nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet Hibernate+SpringMVC -

sql - Postgresql tables exists, but getting "relation does not exist" when querying -

asp.net mvc - breakpoint on javascript in CSHTML? -