Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to copy a symlink file on Mac?
QtWS25 Last Chance

How to copy a symlink file on Mac?

Scheduled Pinned Locked Moved General and Desktop
7 Posts 3 Posters 5.5k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    viktor.benei
    wrote on 30 Jan 2012, 21:16 last edited by
    #1

    We have to copy symbolic link files on Mac OS, but the QFile::copy fails.

    We've tried to get the symLinkTarget() as well but it returns absolute target path and we have to support relative symlink targets as well.

    Can anyone suggest a solution for copying symlinks as files?

    1 Reply Last reply
    0
    • L Offline
      L Offline
      leon.anavi
      wrote on 30 Jan 2012, 23:10 last edited by
      #2

      If you want to copy only the symbolic link only try the following idea:

      Check if selected files is a symlink using "QFileInfo::isSymLink":http://developer.qt.nokia.com/doc/qt-4.8/qfileinfo.html#isSymLink

      If it is a symlink get absolute path to the file that the links point to using "QFileInfo::symLinkTarget ()":http://developer.qt.nokia.com/doc/qt-4.8/qfileinfo.html#symLinkTarget

      Create a copy of the link using "QFile::link":http://developer.qt.nokia.com/doc/qt-4.8/qfile.html#link

      http://anavi.org/

      1 Reply Last reply
      0
      • V Offline
        V Offline
        viktor.benei
        wrote on 30 Jan 2012, 23:53 last edited by
        #3

        Thanks leon, we tried it, but QFileInfo::symLinkTarget() returns the absolute path of the target and we have to support relative pathes as well as absolute ones.

        1 Reply Last reply
        0
        • L Offline
          L Offline
          leon.anavi
          wrote on 31 Jan 2012, 08:20 last edited by
          #4

          [quote author="viktor.benei" date="1327967601"]Thanks leon, we tried it, but QFileInfo::symLinkTarget() returns the absolute path of the target and we have to support relative pathes as well as absolute ones.[/quote]

          My idea was to create a new sym link using a relative path as an argument of QFile::link ( const QString & linkName ) at step 3.

          http://anavi.org/

          1 Reply Last reply
          0
          • V Offline
            V Offline
            viktor.benei
            wrote on 31 Jan 2012, 09:29 last edited by
            #5

            leon: thanks. We tried that one as well. The problem: you cannot get the stored target of a symlink file in Qt. It returns absolute path every time, even if the symlink file points relative.

            We have to copy a whole folder-tree. So if we 'copy' symlinks the way you suggested, the symlinks will point either to the original files (if we use symlink-target as absolute path) or relatively, which can mess up absolute symlink pathes.

            We use this copying to make backup of applications, folders, etc. before operating on them, so we have to support both absolute and relative pathes.

            1 Reply Last reply
            0
            • V Offline
              V Offline
              viktor.benei
              wrote on 31 Jan 2012, 09:38 last edited by
              #6

              Currently this is what we do (it works, but it's platform dependent):

              • on Windows we simply QFile::copy the shortcuts and symlinks (only junk-link seems to be an issue when we try to delete them, because just-links are readonly)
              • on Mac we get the symlink's target with Carbon (it returns the actual target: if it's a relative path then a relative one, if points to an absolute path it returns an absolute one) and use it as target for QFile::link()
                ** there's only 1 exception: aliases, but we don't have to support Mac aliases currently (aliases are detected as symlinks in Qt, but you cannot get an alias' target with Qt nor with the Carbon solution we use)

              Why can't we get symlink-targets as they are in Qt? Why is it an absolute path in every case? It makes this type of copying really hard...

              1 Reply Last reply
              0
              • G Offline
                G Offline
                goetz
                wrote on 31 Jan 2012, 11:56 last edited by
                #7

                On the Mac, you could try to use "/bin/cp" in a QProcess instead of QFile::copy() to achieve this. It preserves the symlinks.

                http://www.catb.org/~esr/faqs/smart-questions.html

                1 Reply Last reply
                0

                7/7

                31 Jan 2012, 11:56

                • Login

                • Login or register to search.
                7 out of 7
                • First post
                  7/7
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved