Beispiel #1
0
/* GetPathModDate
 *  extract mod date from a path
 */
rc_t KDBVGetPathModDate ( const KDirectory *dir,
    KTime_t *mtime, const char *path, va_list args )
{
    rc_t rc;
    uint32_t ptype;
    const KDirectory *obj_dir;

    va_list cpy;
    va_copy ( cpy, args );
    ptype = KDirectoryVPathType ( dir, path, cpy );
    va_end ( cpy );

    switch ( ptype )
    {
    case kptDir:
    case kptDir | kptAlias:
        break;

    default:
        return KDirectoryVDate ( dir, mtime, path, args );
    }

    * mtime = 0;
    rc = KDirectoryVOpenDirRead ( dir, & obj_dir, true, path, args );
    if ( rc == 0 )
    {
        rc = KDBGetObjModDate ( obj_dir, mtime );
        KDirectoryRelease ( obj_dir );
    }

    return rc;
}
Beispiel #2
0
 /* Date
 *  get date/time to object
 *
 *  "date" [ OUT ] - return parameter
 *
 *  "path" [ IN ] - NUL terminated string in directory-native
 *  character set denoting target object
 */
 inline rc_t Date ( KTime_t *date, const char *path, ... ) const throw ()
 {
    va_list args;
    va_start ( args, path );
    rc_t rc = KDirectoryVDate ( this, date, path, args );
    va_end ( args );
    return rc;
 }
Beispiel #3
0
static
rc_t CCCopyDoFile (CCCopy * self)
{
    const KFile * original;
    rc_t rc = 0;
    enum KCreateMode mode;
    
    PLOGMSG (klogDebug9, "CCCopyDoFile $(f)", PLOG_S(f), self->path);

    if (! self->force)
    {
	/* if not forced replace mode we fail on existing file */
	mode = kcmCreate;
    }
    else
    {
	uint32_t tt;

	tt = KDirectoryPathType (self->out, self->path);
	switch (tt)
	{
	default:
	    PLOGMSG (klogWarn, "File exists and will be replaced in output directory $(f)",
		     PLOG_S(f), self->path);
	    break;
	    /* if the path to the file or the file do not exist no warning */
	case kptNotFound:
	case kptBadPath:
	    break;
	}
	tt = KDirectoryPathType (self->xml, self->path);
	switch (tt)
	{
	default:
	    PLOGMSG (klogWarn, "File exists and might be replaced in xml directory $(f)",
		     PLOG_S(f), self->path);
	    break;
	    /* if the path to the file or the file do not exist no warning */
	case kptNotFound:
	case kptBadPath:
	    break;
	}

	/* forced mode we create with init instead of create forcing a delete/create effect */
	mode = kcmInit;
    }

    /* open original source for read */
    rc = KDirectoryVOpenFileRead (self->in, &original, self->path, NULL);
    if (rc == 0)
    {
	KFile * copy;

	/* create copy output for write */
	rc = KDirectoryVCreateFile (self->out, &copy, false, 0644, mode|kcmParents,
				    self->path, NULL);
	if (rc == 0)
	{
	    KFile * fm;

	    /* create parallel <path>.md5 */
	    rc = KDirectoryCreateFile (self->out, &fm, true, 0644, mode, "%s.md5",
				       self->path);
	    if (rc == 0)
	    {
		KMD5SumFmt * md5f;

		/* make the .md5 an MD5 sum format file */
		rc = KMD5SumFmtMakeUpdate (&md5f, fm);
		if (rc == 0)
		{
		    union u
		    {
			KFile * kf;
			KMD5File * mf;
		    } outf;

		    /* combine the copy and MD5 file into our special KFile */
		    rc = KMD5FileMakeWrite (&outf.mf, copy, md5f, self->path);
		    if (rc == 0)
		    {
			const KFile * inf;

			/* release this outside reference to the MD5SumFMT leaving
			 * only the one internal to the KMD5File */
			KMD5SumFmtRelease (md5f);

			/* create the KTeeFile that copies reads from the
			 * original as writes to the copy.  Reads will be
			 * made by the cataloging process */
			rc = KFileMakeTeeRead (&inf, original, outf.kf);
			if (rc == 0)
			{
			    CCCat * po;
			    KTime_t mtime;

			    /* try to get a modification time for this pathname */
			    rc = KDirectoryVDate (self->in, &mtime, self->path, NULL);
			    if (rc != 0)
				mtime = 0;	/* default to ? 0? */

			    /* create the cataloger giving it the infile which
			     * is the KTeeFile, Indirectory, the XML directory,
			     * and the original path for the file */

			    rc = CCCatMake (&po, self->in, self->xml, inf, self->md5,
					    self->ff, mtime, self->tree, false, 0, self->path);
			    if (rc == 0)
			    {
				/* do the catalog (and thus copy) */
				rc = CCCatDo(po);
				/* release the cataloger object */
				CCCatRelease (po);
			    }
			    else
				pLOGERR (klogDebug6, rc, "failure in CCCatMake $(P)",
				     PLOG_S(P), self->path);
			    /* release the infile which will complete a  copy 
			     * regardless of the state of the cataloger */
			    KFileRelease (inf);
/* 			    return rc; */
			}
			else
			{
			    KFileRelease (outf.kf);
			    KFileRelease (original);
			    pLOGERR (klogDebug4, rc, "failure with kfilemaketeeread $(P)",
				     PLOG_S(P), self->path);
			} /* rc = KFileMakeTeeRead (&inf, original, outf.kf);*/
		    }
		    else
		    {
			KFileRelease (copy);
			KMD5SumFmtRelease (md5f);
			pLOGERR (klogDebug4, rc, "failure with KMD5FileMakeWrite $(P)",
				 PLOG_S(P), self->path);
		    } /* KMD5FileMakeWrite (&outf.mf, copy, md5f, self->path); */
		} /* KDirectoryCreateFile (self->out, &fm, true, 0644, mode, "%s.md5", */
		else
		    pLOGERR (klogDebug4, rc, "failure with KMD5SumFmtMakeUpdate $(P)",
			     PLOG_S(P), self->path);

		KFileRelease (fm);
	    } /* KDirectoryCreateFile (self->out, &fm, true, 0644, mode, "%s.md5", */
	    else
		pLOGERR (klogDebug4, rc, "failure with KDirectoryCreateFile $(P).md5",
			 PLOG_S(P), self->path);
	    KFileRelease (copy);
	} /* rc = KDirectoryVCreateFile (self->out, &copy, false, 0644, mode|kcmParents, */
	else
	    pLOGERR (klogDebug4, rc, "failure with KDirectoryVCreateFile $(P)",
		     PLOG_S(P), self->path);
	KFileRelease (original);
    } /* rc = KDirectoryVOpenFileRead (self->in, &original, self->path, NULL); */
    else
	pLOGERR (klogDebug4, rc, "failure with KDirectoryVOpenFileRead $(pP)",
		 PLOG_S(P), self->path);
    return rc;
}
Beispiel #4
0
 inline rc_t Date ( KTime_t *date, const char *path,
    va_list args ) const throw ()
 { return KDirectoryVDate ( this, date, path, args ); }