Changeset 167 for trunk/src/sh_unix.c


Ignore:
Timestamp:
Mar 15, 2008, 12:38:20 PM (17 years ago)
Author:
katerina
Message:

First parts of changes for MODI_TXT

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/sh_unix.c

    r162 r167  
    30623062     
    30633063       /* return */
     3064      if (tmpFile.link_path)   SH_FREE(tmpFile.link_path);
    30643065      SL_RETURN( 0, _("sh_unix_checksum_size"));
    30653066    }
    30663067
    30673068 out:
     3069  if (tmpFile.link_path)   SH_FREE(tmpFile.link_path);
    30683070  sl_strlcpy(fileHash, SH_KEY_NULL, KEY_LEN+1);
    30693071  SL_RETURN( -1, _("sh_unix_checksum_size"));
     
    32793281  int           fd;
    32803282  int           fstat_return;
    3281 
     3283  sh_string   * content = NULL;
     3284     
    32823285  time_t        tend;
    32833286  time_t        tstart;
     
    33023305  fstat_return = -1;
    33033306  rval_open    = -1;
     3307
     3308  theFile->link_path = NULL;
    33043309
    33053310  if (stat_return == 0 && S_ISREG(buf.st_mode))
     
    33963401              char hashbuf[KEYBUF_SIZE];
    33973402              UINT64 length_nolim = TIGER_NOLIM;
     3403
     3404              if ((theFile->check_mask & MODI_TXT) != 0 && fbuf.st_size < SH_TXT_MAX)
     3405                {
     3406                  sl_init_content (rval_open, fbuf.st_size);
     3407                }
     3408
    33983409              sl_strlcpy(fileHash,
    33993410                         sh_tiger_generic_hash (theFile->fullpath,
     
    34023413                                                hashbuf, sizeof(hashbuf)),
    34033414                         KEY_LEN+1);
     3415
     3416              content = sl_get_content(rval_open);
     3417
    34043418              if ((theFile->check_mask & MODI_SGROW) != 0)
    34053419                {
     
    34393453              char hashbuf[KEYBUF_SIZE];
    34403454              UINT64 length_nolim = TIGER_NOLIM;
     3455
     3456              if ((theFile->check_mask & MODI_TXT) != 0 && fbuf.st_size < SH_TXT_MAX)
     3457                {
     3458                  sl_init_content (rval_open, fbuf.st_size);
     3459                }
     3460
    34413461              sl_strlcpy(fileHash,
    34423462                         sh_tiger_generic_hash (theFile->fullpath, rval_open,
     
    34453465                                                hashbuf, sizeof(hashbuf)),
    34463466                         KEY_LEN + 1);
     3467
     3468              content = sl_get_content(rval_open);
     3469
    34473470              if ((theFile->check_mask & MODI_SGROW) != 0)
    34483471                {
     
    36173640  if (theFile->c_mode[0] == 'l')
    36183641    {
    3619 
    36203642      linknamebuf = SH_ALLOC(PATH_MAX);
    36213643
     
    36373659          SH_FREE(tmp2);
    36383660          SH_FREE(linknamebuf);
    3639           theFile->linkpath[0] = '-';
    3640           theFile->linkpath[1] = '\0';
     3661          theFile->link_path = sh_util_strdup("-");
    36413662          SL_RETURN((-1),_("sh_unix_getinfo"));
    36423663        }
    36433664
    3644     if (linknamebuf[0] == '/')
    3645       {
    3646         sl_strlcpy (theFile->linkpath, linknamebuf, PATH_MAX);
    3647       }
    3648     else
    3649       {
    3650         tmp = sh_util_dirname(theFile->fullpath);
    3651         if (tmp) {
    3652           sl_strlcpy (theFile->linkpath, tmp, PATH_MAX);
     3665      if (linknamebuf[0] == '/')
     3666        {
     3667          theFile->link_path = sh_util_strdup (linknamebuf);
     3668        }
     3669      else
     3670        {
     3671          tmp = sh_util_dirname(theFile->fullpath);
     3672          if (tmp) {
     3673            theFile->link_path = SH_ALLOC(PATH_MAX);
     3674            sl_strlcpy (theFile->link_path, tmp, PATH_MAX);
     3675            SH_FREE(tmp);
     3676          } else {
     3677            theFile->link_path = SH_ALLOC(PATH_MAX);
     3678            theFile->link_path[0] = '\0';
     3679          }
     3680          /*
     3681           * Only attach '/' if not root directory. Handle "//", which
     3682           * according to POSIX is implementation-defined, and may be
     3683           * different from "/" (however, three or more '/' will collapse
     3684           * to one).
     3685           */
     3686          tmp = theFile->link_path; while (*tmp == '/') ++tmp;
     3687          if (*tmp != '\0')
     3688            {
     3689              sl_strlcat (theFile->link_path, "/", PATH_MAX);
     3690            }
     3691          sl_strlcat (theFile->link_path, linknamebuf, PATH_MAX);
     3692        }
     3693     
     3694      /* stat the link
     3695       */
     3696      stat_return = retry_lstat (FIL__, __LINE__, theFile->link_path, &lbuf);
     3697     
     3698      /* check for error
     3699       */
     3700      if (stat_return != 0)
     3701        {
     3702          stat_return = errno;
     3703          tmp  = sh_util_safe_name (theFile->fullpath);
     3704          tmp2 = sh_util_safe_name (theFile->link_path);
     3705          if (stat_return != ENOENT)
     3706            {
     3707              char errbuf[SH_ERRBUF_SIZE];
     3708              sh_error_handle (level, FIL__, __LINE__, stat_return,
     3709                               MSG_FI_LSTAT,
     3710                               sh_error_message (stat_return,errbuf, sizeof(errbuf)),
     3711                               tmp2);
     3712            }
     3713          else
     3714            {
     3715              /* a dangling link -- everybody seems to have plenty of them
     3716               */
     3717              sh_error_handle ((-1), FIL__, __LINE__, 0, MSG_FI_DLNK,
     3718                               tmp, tmp2);
     3719            }
     3720          theFile->linkisok = BAD;
    36533721          SH_FREE(tmp);
    3654         } else {
    3655           theFile->linkpath[0] = '\0';
    3656         }
    3657         /*
    3658          * Only attach '/' if not root directory. Handle "//", which
    3659          * according to POSIX is implementation-defined, and may be
    3660          * different from "/" (however, three or more '/' will collapse
    3661          * to one).
    3662          */
    3663         tmp = theFile->linkpath; while (*tmp == '/') ++tmp;
    3664         if (*tmp != '\0')
    3665           {
    3666             sl_strlcat (theFile->linkpath, "/", PATH_MAX);
    3667           }
    3668         sl_strlcat (theFile->linkpath, linknamebuf, PATH_MAX);
    3669       }
    3670    
    3671     /* stat the link
    3672      */
    3673     stat_return = retry_lstat (FIL__, __LINE__, theFile->linkpath, &lbuf);
    3674 
    3675     /* check for error
    3676      */
    3677     if (stat_return != 0)
    3678       {
    3679         stat_return = errno;
    3680         tmp  = sh_util_safe_name (theFile->fullpath);
    3681         tmp2 = sh_util_safe_name (theFile->linkpath);
    3682         if (stat_return != ENOENT)
    3683           {
    3684             char errbuf[SH_ERRBUF_SIZE];
    3685             sh_error_handle (level, FIL__, __LINE__, stat_return,
    3686                              MSG_FI_LSTAT,
    3687                              sh_error_message (stat_return,errbuf, sizeof(errbuf)),
    3688                              tmp2);
    3689           }
    3690         else
    3691           {
    3692             /* a dangling link -- everybody seems to have plenty of them
    3693              */
    3694             sh_error_handle ((-1), FIL__, __LINE__, 0, MSG_FI_DLNK,
    3695                              tmp, tmp2);
    3696           }
    3697         theFile->linkisok = BAD;
    3698         SH_FREE(tmp);
    3699         SH_FREE(tmp2);
    3700         SH_FREE(linknamebuf);
    3701         /*
    3702          * changed Tue Feb 10 16:16:13 CET 2004:
    3703          *  add dangling symlinks into database
    3704          * SL_RETURN((-1),_("sh_unix_getinfo"));
    3705          */
    3706         theFile->linkmode = 0;
    3707         SL_RETURN((0),_("sh_unix_getinfo"));
    3708       }
    3709 
    3710     theFile->linkisok = GOOD;
     3722          SH_FREE(tmp2);
     3723          SH_FREE(linknamebuf);
     3724          /*
     3725           * changed Tue Feb 10 16:16:13 CET 2004:
     3726           *  add dangling symlinks into database
     3727           * SL_RETURN((-1),_("sh_unix_getinfo"));
     3728           */
     3729          theFile->linkmode = 0;
     3730          SL_RETURN((0),_("sh_unix_getinfo"));
     3731        }
    37113732     
    3712 
    3713     /* --- Determine file type. ---
    3714      */
    3715     sh_unix_getinfo_type (&lbuf, &type, theFile->link_c_mode);
    3716     theFile->type = type;
    3717  
    3718     /* --- Determine permissions. ---
    3719      */
    3720     sh_unix_getinfo_mode (&lbuf, &mode, theFile->link_c_mode);
    3721     theFile->linkmode = lbuf.st_mode;
    3722 
    3723     /* --- Output the link. ---
    3724      */
    3725     if (theFile->linkisok == GOOD)
    3726       {
    3727         tmp2 = sh_util_safe_name (linknamebuf);     
    3728         sh_error_handle ((-1), FIL__, __LINE__, 0, MSG_FI_LLNK,
    3729                          theFile->link_c_mode, tmp2);
    3730         SH_FREE(tmp2);
    3731       }
    3732     SH_FREE(linknamebuf);
    3733   } 
     3733      theFile->linkisok = GOOD;
     3734     
     3735     
     3736      /* --- Determine file type. ---
     3737       */
     3738      sh_unix_getinfo_type (&lbuf, &type, theFile->link_c_mode);
     3739      theFile->type = type;
     3740     
     3741      /* --- Determine permissions. ---
     3742       */
     3743      sh_unix_getinfo_mode (&lbuf, &mode, theFile->link_c_mode);
     3744      theFile->linkmode = lbuf.st_mode;
     3745     
     3746      /* --- Output the link. ---
     3747       */
     3748      if (theFile->linkisok == GOOD)
     3749        {
     3750          tmp2 = sh_util_safe_name (linknamebuf);     
     3751          sh_error_handle ((-1), FIL__, __LINE__, 0, MSG_FI_LLNK,
     3752                           theFile->link_c_mode, tmp2);
     3753          SH_FREE(tmp2);
     3754        }
     3755      SH_FREE(linknamebuf);
     3756    }
     3757  else /* not a link */
     3758    {
     3759      if (content)
     3760        {
     3761          sh_util_base64_enc_alloc (&(theFile->link_path),
     3762                                    sh_string_str(content),
     3763                                    sh_string_len(content));
     3764        }
     3765    }
    37343766  SL_RETURN((0),_("sh_unix_getinfo"));
    37353767}
Note: See TracChangeset for help on using the changeset viewer.