コード例 #1
0
ファイル: hcache.c プロジェクト: larus/jamplus
void filecache_update(TARGET *t)
{
	MD5SUM blobmd5sum;
	int haveblobmd5sum = 0;
	const char *cachedname;
	const char *blobname;
	int cacheerror;

	if (!t->filecache_generate)
		return;

	/* If the buildmd5sum is empty, then the file doesn't exist. */
	cacheerror = ismd5empty(t->buildmd5sum);
	if (cacheerror)
		return;

	haveblobmd5sum = 0;
	cachedname = filecache_getfilename(t, t->buildmd5sum, NULL);
	if (!cachedname)
		return;

	/* Search for the appropriate .link file that matches the target. */
	haveblobmd5sum = filecache_findlink(cachedname, blobmd5sum);

	/* If we weren't able to determine the target md5sum, do it now. */
	if (!haveblobmd5sum)
	{
#ifdef OPT_BUILTIN_LUA_SUPPORT_EXT
		LIST *md5callback;

		pushsettings( t->settings );
		md5callback = var_get( "MD5CALLBACK" );
		popsettings( t->settings );

		if ( md5callback )
		{
			luahelper_md5callback(t->boundname, blobmd5sum, md5callback->string);
		}
		else
		{
#endif
			md5file(t->boundname, blobmd5sum);
#ifdef OPT_BUILTIN_LUA_SUPPORT_EXT
		}
#endif
		memcpy(t->contentmd5sum, blobmd5sum, sizeof(MD5SUM));
		if (ismd5empty(t->contentmd5sum))
			return;
	}

	{
		/* Is the blob already there? */
		time_t blobtime;
		blobname = filecache_getfilename(t, blobmd5sum, ".blob");
		if (file_time(blobname, &blobtime) == -1)
		{
			time_t blobpartialtime;
			const char *blobpartialname;

			if(DEBUG_MD5HASH)
				printf("Caching %s as %s\n", t->name, cachedname);
			else
				printf("Caching %s\n", t->name);

			/* Write the new .blob to the cache. */
			blobpartialname = filecache_getfilename(t, blobmd5sum, ".blob.partial");
			if (file_time(blobpartialname, &blobpartialtime) == -1)
			{
				if (copyfile(blobpartialname, t->boundname, &blobmd5sum) == 0  ||
					rename(blobpartialname, blobname) != 0)
				{
					printf("** Unable to write %s to cache.\n", t->name, cachedname);
					filecache_disable(t);
					return;
				}
			}
		}
	}

	/* Write the new .link file to the cache. */
	{
		FILE *file;
		BUFFER linknamebuff;
		buffer_init(&linknamebuff);
		buffer_addstring(&linknamebuff, cachedname, strlen(cachedname));
		buffer_addchar(&linknamebuff, '-');
		buffer_addstring(&linknamebuff, md5tostring(blobmd5sum), 32);
		buffer_addstring(&linknamebuff, ".link", 5);
		buffer_addchar(&linknamebuff, 0);

		file_mkdir(buffer_ptr(&linknamebuff));
		file = fopen(buffer_ptr(&linknamebuff), "wb");
		if (file)
		{
			write_md5sum(file, blobmd5sum);
			write_string(file, t->name);
			fclose(file);
		}

		buffer_free(&linknamebuff);
	}
}
コード例 #2
0
ファイル: hcache.c プロジェクト: larus/jamplus
/*
 * Get cached md5sum of a file. If none found, or not up to date, if the file is source
 * try to recalculate the sum. If not, then return empty sum (all zeroes).
 */
int getcachedmd5sum( TARGET *t, int source )
{
	HCACHEDATA cachedata, *c = &cachedata;
	int  use_cache = 1;
	HCACHEFILE *file;
	const char *target = t->boundname;
# ifdef DOWNSHIFT_PATHS
	char path[ MAXJPATH ];
	char *p;
#endif

	if ( t->contentmd5sum_calculated )
		return t->contentmd5sum_changed;

	if (!source) {
		memset(&t->buildmd5sum, 0, sizeof(t->buildmd5sum));
		memset(&t->contentmd5sum, 0, sizeof(t->contentmd5sum));
		t->contentmd5sum_calculated = 1;
		t->contentmd5sum_changed = 0;
		return t->contentmd5sum_changed;
	}

	file = hcachefile_get( t );

	++queries;

# ifdef DOWNSHIFT_PATHS
	p = path;

	do *p++ = (char)tolower( *target );
	while( *target++ );

	target = path;
# endif

	c->boundname = target;

	if( hashcheck( file->hcachehash, (HASHDATA **) &c ) )
	{
		if ( t->time == 0 ) {
			/* This file was generated.  Grab its timestamp. */
			file_time( c->boundname, &c->mtime );
		} else if( c->mtime != t->time )
			use_cache = 0;

		if ( use_cache ) {
			use_cache = memcmp(md5sumempty, &c->contentmd5sum, sizeof(c->contentmd5sum)) != 0;
		}

		if( use_cache ) {
			if( DEBUG_MD5HASH )
				printf( "- content md5: %s (%s)\n", t->boundname, md5tostring(c->contentmd5sum));
			c->age = 0; /* The entry has been used, its young again */
			++hits;
			t->contentmd5sum_changed = 0;
			memcpy(&t->contentmd5sum, &c->contentmd5sum, sizeof(t->contentmd5sum));
			t->contentmd5sum_calculated = 1;
			return t->contentmd5sum_changed;
		}
		else {
			if( DEBUG_MD5HASH )
				printf( "md5 cache out of date for %s (time %d, md5time %d)\n", t->boundname , (int)t->time, (int)c->mtime );
		}
	} else {
		if( hashenter( file->hcachehash, (HASHDATA **)&c ) ) {
			c->boundname = newstr( c->boundname );
			c->next = file->hcachelist;
			file->hcachelist = c;
			c->time = 0;
			c->includes = NULL;
			c->hdrscan = NULL;
		}
	}

	file->dirty = 1;

	/* 'c' points at the cache entry.  Its out of date. */

	{
		MD5SUM origmd5sum;
#ifdef OPT_BUILTIN_LUA_SUPPORT_EXT
		LIST *md5callback;
#endif

		memcpy( &origmd5sum, &c->contentmd5sum, sizeof( MD5SUM ) );
#ifdef OPT_BUILTIN_LUA_SUPPORT_EXT
		pushsettings( t->settings );
		md5callback = var_get( "MD5CALLBACK" );
		popsettings( t->settings );

		if ( md5callback )
		{
			luahelper_md5callback(t->boundname, c->contentmd5sum, md5callback->string);
		}
		else
		{
#endif
			md5file( t->boundname, c->contentmd5sum );
#ifdef OPT_BUILTIN_LUA_SUPPORT_EXT
		}
#endif
		t->contentmd5sum_changed = memcmp( &origmd5sum, &c->contentmd5sum, sizeof( MD5SUM ) ) != 0;
	}
	if( DEBUG_MD5HASH )
		printf( "- content md5: %s (%s)\n", t->boundname, md5tostring(c->contentmd5sum));

	c->mtime = t->time;
	if ( c->mtime == 0 ) {
		/* This file was generated.  Grab its timestamp. */
		file_time( c->boundname, &c->mtime );
	}
	c->age = 0;
	memcpy(&t->contentmd5sum, &c->contentmd5sum, sizeof(t->contentmd5sum));
	t->contentmd5sum_calculated = (char)(memcmp(md5sumempty, &t->contentmd5sum, sizeof(t->contentmd5sum)) != 0);
	memset(&t->buildmd5sum, 0, sizeof(t->buildmd5sum));

	return t->contentmd5sum_changed;
}
コード例 #3
0
ファイル: hcache.c プロジェクト: caryhaynie/jamplus
/*
 * Get cached md5sum of a file. If none found, or not up to date, if the file is source
 * try to recalculate the sum. If not, then return empty sum (all zeroes).
 */
int getcachedmd5sum( TARGET *t, int forcetimecheck )
{
	CHECKSUMDATA checksumdata, *c = &checksumdata;

	checksums_readfile();

	if ( t->contentchecksum == NULL ) {
		const char *target = t->boundname;
# ifdef DOWNSHIFT_PATHS
		char path[ MAXJPATH ];
		char *p = path;

		do *p++ = (char)tolower( *target ); while( *target++ );

		target = path;
# endif

		c->boundname = target;

		if ( !hashcheck( checksumhash, (HASHDATA **) &c ) ) {
			if ( hashenter( checksumhash, (HASHDATA **)&c ) ) {
				c->boundname = newstr( c->boundname );
				c->next = checksumdatalist;
				checksumdatalist = c;
				c->mtime = 0;
				memset( &c->contentmd5sum, 0, MD5_SUMSIZE );
				c->contentmd5sum_changed = 1;
				c->contentmd5sum_calculated = 0;
				c->age = 0;
			}
		}

		t->contentchecksum = c;
	} else {
		c = t->contentchecksum;
	}

	if ( !c->contentmd5sum_calculated  ||  forcetimecheck  ||  t->time != c->mtime  ||  c->mtime == 0 ) {
		/* This file may have generated or updated in another fashion.  Grab its timestamp. */
		time_t ftime;

		c->contentmd5sum_calculated = 1;

//		if ( file_time( c->boundname, &ftime ) == -1 ) {
		timestamp( c->boundname, &ftime, 0 );
		if ( ftime == 0 ) {
			/* This file is not present anymore. */
			c->age = 0; /* The entry has been used, its young again */
			c->mtime = 0;
			c->contentmd5sum_changed = 1;
			memset( &c->contentmd5sum, 0, MD5_SUMSIZE );
			checksumsdirty = 1;
			return 1;
		}

		/* 'c' points at the cache entry.  Its out of date. */

		if ( ftime != c->mtime )
		{
			MD5SUM origmd5sum;
#ifdef OPT_BUILTIN_LUA_SUPPORT_EXT
			SETTINGS *md5callback;
#endif

			memcpy( &origmd5sum, &c->contentmd5sum, sizeof( MD5SUM ) );
#ifdef OPT_BUILTIN_LUA_SUPPORT_EXT
			md5callback = quicksettingslookup( t, "MD5CALLBACK" );

			if ( md5callback && md5callback->value )
			{
				luahelper_md5callback(t->boundname, c->contentmd5sum, list_value(list_first(md5callback->value)));
			}
			else
			{
#endif
				md5file( t->boundname, c->contentmd5sum );
#ifdef OPT_BUILTIN_LUA_SUPPORT_EXT
			}
#endif
			c->mtime = ftime;
			c->contentmd5sum_changed = memcmp( &origmd5sum, &c->contentmd5sum, sizeof( MD5SUM ) ) != 0;
		}
		//if( DEBUG_MD5HASH )
			//printf( "- content md5: %s (%s)\n", t->boundname, md5tostring(c->contentmd5sum));

		c->age = 0;
		checksumsdirty = 1;
	}

	return c->contentmd5sum_changed;

#if 0
			if( DEBUG_MD5HASH )
				printf( "md5 cache out of date for %s (time %d, md5time %d)\n", t->boundname , (int)t->time, (int)c->mtime );
#endif
}