c:copy command and links

A forum for general AmigaOS 4.x support questions that are not platform-specific

Re: c:copy command and links

Postby ChrisH » Tue Sep 27, 2011 1:43 am

xenic wrote:I created 2 SOFT links in a directory on an SFS partition; one was relative and the other absolute.

I just tried using C:MakeLink to create a soft link with a relative path, and it ended-up being absolute, so I'm not even sure how you can create one normally!
User avatar
ChrisH
Beta Tester
Beta Tester
 
Posts: 915
Joined: Mon Dec 20, 2010 10:09 pm

Re: c:copy command and links

Postby xenic » Tue Sep 27, 2011 3:10 am

ChrisH wrote:
xenic wrote:I created 2 SOFT links in a directory on an SFS partition; one was relative and the other absolute.

I just tried using C:MakeLink to create a soft link with a relative path, and it ended-up being absolute, so I'm not even sure how you can create one normally!

Works for me. I assume that you realize that relative means "relative to the current directory" and changed directories to the one where the file is located. Here is what I did to create a relative link in a directory in ram:

makedir ram:test
copy anyfile TO ram:test
CD ram:test
makelink testfile TO anyfile SOFT

or to demonstrate relative linking to a file in a different directory:

makedir ram:test
copy anyfile TO ram:t
cd ram:test
makelink testlink TO /T/anyfile SOFT

It works for me. Hard links work differently. It appears that hard links are always absolute. That's strange since hard links can only be made to files on the same volume (partition). I would think they would always be relative. I don't think hard links work on SFS but I could be wrong about that. Are you using hard links instead of soft ones?? If so, that's one reason I think makelink should be changed to default to SOFT links instead of hard links. Hard links are next to useless for various reasons.
AmigaOne X1000 with 2GB memory - OS4.1 FE
xenic
 
Posts: 1160
Joined: Sun Jun 19, 2011 1:06 am

Re: c:copy command and links

Postby ChrisH » Tue Sep 27, 2011 6:03 pm

@xenic
I think I've been fooled by Filer. It shows relative path links as absolute paths, for some reason. Damn confusing! The "C:List" command shows it correctly.

EDIT: It appears that my code has the same problem as Filer: When it reads a soft link with a relative path, I actually get an absolute path :( . No doubt there is some trick to this, but reading the path of a link is a fair bit of "black magic" for me... Perhaps someone can spot what I did wrong with my E code:
Code: Select all
PROC easyReadLink(path:ARRAY OF CHAR) RETURNS linkPath:STRING
   DEF devProc:PTR TO devproc, len, buf:ARRAY OF CHAR, bufSize
   
   WHILE devProc := GetDeviceProc(path, devProc)
   ENDWHILE IF devProc.flags AND DVPF_ASSIGN = 0
   
   IF devProc
      ->try to retrieve (soft/hard) link path
      NEW buf[bufSize := 256]
      REPEAT
         buf[0] := 0      ->in case ReadLink() returns len=TRUE (for success)
         len := ReadLink(devProc.port, devProc.lock, path, buf, bufSize)
         IF len = -2
            ->(buffer too small)
            END buf
            NEW buf[bufSize := bufSize*2]
         ENDIF
      UNTIL len <> -2
      
      IF len = -1
         ->(could mean "error" OR "success") so determine which
         IF buf[0] <> 0 THEN len := StrLen(buf)
      ENDIF
      
      ->store link path
      IF len > 0
         NEW linkPath[len]
         StrCopy(linkPath, buf)
      ENDIF
   ENDIF
FINALLY
   IF devProc THEN FreeDeviceProc(devProc)
   END buf
ENDPROC
User avatar
ChrisH
Beta Tester
Beta Tester
 
Posts: 915
Joined: Mon Dec 20, 2010 10:09 pm

Re: c:copy command and links

Postby xenic » Wed Sep 28, 2011 2:25 am

@ChrisH
To begin with you are using a deprecated function (i.e. ReadLink). That means it's essentially an OS3 function. Even though soft links were supposedly fixed in v37, maybe ReadLink() wasn't changed to read relative links because hard links are apparently always absolute. Most OS3 users I knew still thought soft links didn't work even after v37 and always used hard links. The only possibility I can think of is that the link path returned by ReadLink depends on the "path" argument and the "lock" that it is relative to. If that isn't the case then it's another useless function; at least for link copying purposes. The only thing I can suggest is to use a "lock" on the directory the filelink is in and a "path" of the filelink itself as arguments to ReadLink().
What I can tell you is that I compiled the "Single Level Directoy Scan" example in the ExamineDir() dos autodoc and it correctly identifies hard and soft links and shows soft links as relative. It is possible to get the correct link information if you use the updated OS4 methods.

EDIT: I found an example that works using ReadLink(). Check out the file ListLinks.c at:
http://thomas-rapp.homepage.t-online.de ... index.html
AmigaOne X1000 with 2GB memory - OS4.1 FE
xenic
 
Posts: 1160
Joined: Sun Jun 19, 2011 1:06 am

Re: c:copy command and links

Postby ChrisH » Thu Sep 29, 2011 8:09 pm

xenic wrote:To begin with you are using a deprecated function (i.e. ReadLink). That means it's essentially an OS3 function.

OS3 stuff should work (backwards compatibility), and if I want my programs to be portable then using OS3 stuff is usually a good idea (I can always add OS4-specific stuff later, if necessary).

The only possibility I can think of is that the link path returned by ReadLink depends on the "path" argument and the "lock" that it is relative to. If that isn't the case then it's another useless function; at least for link copying purposes.

It is not clear to me how it uses the "lock".

EDIT: I found an example that works using ReadLink(). Check out the file ListLinks.c at:
http://thomas-rapp.homepage.t-online.de ... index.html

Thanks. I tried to duplicate his use of ReadLink() (except without dir scanning), and while it "works", it still gives me an absolute path. Maybe I need to be performing a dir scan to get relative paths? That could be very inefficient for how I want to use ReadLink()...
User avatar
ChrisH
Beta Tester
Beta Tester
 
Posts: 915
Joined: Mon Dec 20, 2010 10:09 pm

Re: c:copy command and links

Postby ChrisH » Thu Sep 29, 2011 8:19 pm

ChrisH wrote:Thanks. I tried to duplicate his use of ReadLink() (except without dir scanning), and while it "works", it still gives me an absolute path. Maybe I need to be performing a dir scan to get relative paths? That could be very inefficient for how I want to use ReadLink()...

OK, I solved it! The "lock" needs to be on the parent directory, and the supplied "path" should just be the relative filename (i.e. use FilePart). So for PortablE I now have the following line:
len := ReadLink(Baddr(lock)::filelock.task, lock, FilePart(path), buf, bufSize)

(BTW, without modification that line won't compile until the next beta release of PortablE r6, due to a minor change I made to Baddr().)

Thanks for your pointer to a working example :-)
User avatar
ChrisH
Beta Tester
Beta Tester
 
Posts: 915
Joined: Mon Dec 20, 2010 10:09 pm

Re: c:copy command and links

Postby xenic » Fri Sep 30, 2011 5:26 am

@ChrisH
Glad I could help. I just did a Dopus4 search in my sourcecode examples directory and found that file. I download all the Amiga source files I can and I found and downloaded Thomas's files when working on a small project of my own.
AmigaOne X1000 with 2GB memory - OS4.1 FE
xenic
 
Posts: 1160
Joined: Sun Jun 19, 2011 1:06 am

Previous

Return to General AmigaOS

Who is online

Users browsing this forum: No registered users and 5 guests