lfc_perl man page

lfc_perl(3)            Perl Programmers Reference Guide            lfc_perl(3)

[1mNAME[0m
      lfc - Perl interface to the LFC

[1mSYNOPSIS[0m
      [1muse lfc;[0m
      [1mprintf "CNS_LIST_BEGIN is %d0, $lfc::CNS_LIST_BEGIN;[0m

[1mDESCRIPTION[0m
      The lfc module permits you to access the LFC client interface from perl
      programs. The lfc module is a swig wrapping of the  standard  C  inter-
      face.   For  detailed  descriptions of each function see the individual
      man page of each function.

      There follows a series of examples of how to use selected functions and
      how  to retrieve the information returned by them: Examples are finding
      the GUID of an existing entry, listing the replicas of a given GUID and
      setting and retrieving the comment associated with an entry.

[1mEXAMPLE[0m
      #!/usr/bin/perl -w
      use strict;
      use lfc;

      # stat an existing entry in the LFC and print the GUID
      my ($name,$stat,$guid,$res);
      $name = "/grid/dteam/my.test";

      $stat = lfcc::new_lfc_filestatg();
      $res = lfc::lfc_statg($name,undef,$stat);

      if ($res == 0) {
        $guid = lfcc::lfc_filestatg_guid_get($stat);
        print "The GUID for $name is $guid0;
      } else {
        my $err_num = $lfc::serrno;
        my $err_string = lfc::sstrerror($err_num);
        print "There was an error while looking for $name: Error $err_num ($err_string)0;
        exit(1);
      }
      lfcc::delete_lfc_filestatg($stat);

[1mEXAMPLE[0m
      #!/usr/bin/perl -w
      use strict;
      use lfc;

      # list the replicas of a given entry, starting from the GUID
      my ($guid,$listp,$flag,$num_replicas);
      $guid = "6a3164e0-a4d7-4abe-9f76-e3b8882735d1";

      $listp = lfcc::new_lfc_list();
      $flag =  $lfc::CNS_LIST_BEGIN;

      print "Listing replicas for GUID $guid:0;

      $num_replicas=0;

      while(1) {
        my $res = lfc::lfc_listreplica(undef,$guid,$flag,$listp);
        $flag = $lfc::CNS_LIST_CONTINUE;

        if (!defined $res) {
          last;
        } else {
          my $rep_name = lfcc::lfc_filereplica_sfn_get($res);
          print "Replica: $rep_name0;
          $num_replicas++;
        }
      }
      lfc::lfc_listreplica(undef,$guid,$lfc::CNS_LIST_END,$listp);
      lfcc::delete_lfc_list($listp);

      print "Found $num_replicas replica(s)0;

[1mEXAMPLE[0m
      #!/usr/bin/perl -w
      use strict;
      use lfc;

      # setting and retrieving a comment on a file
      my ($file,$res,$bufspec,$buffer,$comment);
      $file = "/grid/dteam/my.test";

      $comment = "MyComment";
      $res = lfc::lfc_setcomment($file,$comment);

      if ($res != 0) {
        my $err_num = $lfc::serrno;
        my $err_string = lfc::sstrerror($err_num);
        print "Problem while setting comment for $file: Error $err_num ($err_string)0;
        exit(1);
      }

      $bufspec =  "x".($lfc::CA_MAXCOMMENTLEN+1);
      $buffer = pack($bufspec);
      $res = lfc::lfc_getcomment($file,$buffer);

      if ($res != 0) {
        my $err_num = $lfc::serrno;
        my $err_string = lfc::sstrerror($err_num);
        print "Problem while reading the comment for $file: Error $err_num ($err_string)0;
        exit(1);
      }

      $comment = unpack("Z*", $buffer);
      print "Read back comment $comment0;

[1mNOTES[0m
      The   current   interface   to  the  [1mlfc_getcomment(3)[22m,  [1mlfc_getcwd(3)[22m,
      [1mlfc_readlink(3)[22m, [1mlfc_seterrbuf(3) [22mrequires the passing  of  a  suitably
      allocated buffer (in a similar way to the C functions). However this is
      rather non standard in PERL. A future version of lfc perl interface may
      do  away  with  the  need  to  setup  the buffer before the call and to
      explicitly unpack the result afterwards.

[1mSEE ALSO[0m
      [1mLFC C interface man pages[0m

LFC                      $Date: 2007/02/23 10:03:07 $              lfc_perl(3)