Beispiel #1
0
bool rab::GatherSha1Files( Options const& options, Config const& config, Path_t const& relativePath, 
	FolderInfo::FileInfos_t const& fileInfos, LogOutput_t& out )
{
	int errors = 0;

	for( FolderInfo::FileInfos_t::const_iterator i = fileInfos.begin(); i != fileInfos.end(); ++i )
	{
		FileInfo& fileInfo = **i;

		Path_t fullOld = options.pathToOld / relativePath / fileInfo.name;

		dung::MemoryBlock oldFile;
		if( !dung::ReadWholeFile( fullOld.wstring(), oldFile ) )
		{
			out << "Can't read file " << FileString( fullOld ) << std::endl;
			errors++;
			continue;
		}
		
		dung::SHA1Compute( oldFile.pBlock, oldFile.size, fileInfo.oldSha1 );
		fileInfo.oldSize = oldFile.size;
	}

	return errors == 0;
}
Beispiel #2
0
_tstring rab::FileString( Path_t const& p )
{
#ifdef SCARAB_WCHAR_MODE
	return p.wstring();
#else
	return p.string();
#endif
}
Beispiel #3
0
bool rab::BuildDiffFile( Options const& options, Config const& config, DiffEncoders const& diffEncoders,
	Path_t const& relativePath, PackageOutput_t& package, LogOutput_t& out, FileInfo& fileInfo )
{
	Path_t fullNew = options.pathToNew / relativePath / fileInfo.name;
	Path_t fullOld = options.pathToOld / relativePath / fileInfo.name;
	Path_t relativeTemp = relativePath / DiffFileName(fileInfo.name, config);

	dung::MemoryBlock oldFile;
	if( !ReadWholeFile( fullOld.wstring(), oldFile ) )
	{
		out << "Can't read file " << FileString(fullOld) << std::endl;
		return false;
	}
	
	dung::SHA1Compute( oldFile.pBlock, oldFile.size, fileInfo.oldSha1 );
	fileInfo.oldSize = oldFile.size;

	if( MatchName( config.oldSkipChanged_regex, fileInfo.name ) )
		return true;

	dung::MemoryBlock newFile;
	if( !ReadWholeFile( fullNew.wstring(), newFile ) )
	{
		out << "Can't read file " << FileString(fullNew) << std::endl;
		return false;
	}

	dung::SHA1Compute( newFile.pBlock, newFile.size, fileInfo.newSha1 );
	fileInfo.newSize = newFile.size;

	bool result = true;

	if( fileInfo.newSha1 != fileInfo.oldSha1 )
	{
		fileInfo.isDifferent = true;
		
		result &= CreateDiffFile( options, diffEncoders, fileInfo, fullNew, fullOld, relativeTemp, newFile, oldFile, package, out );
	}
	else
		fileInfo.isDifferent = false;

	return result;
}
Beispiel #4
0
bool rab::CreateDiffFile( Options const& options, DiffEncoders const &diffEncoders, FileInfo& fileInfo, 
	Path_t const& fullNew, Path_t const& fullOld, Path_t const& relativeTemp, 
	dung::MemoryBlock const& newFile, dung::MemoryBlock const& oldFile, PackageOutput_t &package, LogOutput_t& out )
{
	Path_t fullTemp = relativeTemp.filename();

	if( options.produceTemp )
	{
		fullTemp = options.pathToTemp / relativeTemp;
		fs::create_directories( fullTemp.parent_path() );
	}

	dung::DiffEncoder_i* pEncoder = diffEncoders.FindEncoder( fileInfo.name, fileInfo.diffMethod );
	if( pEncoder != NULL )
	{		
		out << "Encoding " << fileInfo.diffMethod << " diff file " << GenericString( relativeTemp ) << std::endl;
		
		dung::MemoryBlock deltaFile;
		if( !pEncoder->EncodeDiffMemoryBlock( newFile.pBlock, newFile.size, oldFile.pBlock, oldFile.size, deltaFile.pBlock, deltaFile.size ) )
		{
			_tstring errorMessage;
			pEncoder->GetErrorMessage( errorMessage );
			out << "Encoding error: " << errorMessage << std::endl;
			return false;
		}

		if( options.produceTemp )
		{
			if( !WriteWholeFile( fullTemp.wstring(), deltaFile ) )
			{
				out << "Can't write file " << GenericString( fullTemp ) << std::endl;
				return false;
			}
		}

		if( !package.WriteFile( GenericString( relativeTemp ), deltaFile.pBlock, deltaFile.size ) )
		{
			out << "Can't write file " << GenericString( relativeTemp ) << " to package. Size=" << deltaFile.size << std::endl;
			return false;
		}
	}
	else
	{
		dung::DiffEncoderExternal_i* pExternalEncoder = diffEncoders.FindExternalEncoder( fileInfo.name, fileInfo.diffMethod );
		if( pExternalEncoder != NULL )
		{
			out << "Encoding " << fileInfo.diffMethod << " diff file " << GenericString( relativeTemp ) << std::endl;
			if( !pExternalEncoder->EncodeDiffFile( GenericString(fullNew).c_str(), GenericString(fullOld).c_str(), GenericString(fullTemp).c_str() ) )
			{
				_tstring errorMessage;
				pExternalEncoder->GetErrorMessage( errorMessage );
				out << "Encoding error: " << errorMessage << std::endl;
				return false;
			}

			dung::MemoryBlock deltaFile;
			if( !ReadWholeFile( fullTemp.generic_string(), deltaFile ) )
			{
				out << "Can't read file " << GenericString(fullTemp) << std::endl;
				return false;
			}

			if( !options.produceTemp )
				fs::remove( fullTemp );

			if( !package.WriteFile( GenericString(relativeTemp), deltaFile.pBlock, deltaFile.size ) )
			{
				out << "Can't write file " << GenericString(relativeTemp) << " to package. Size=" << deltaFile.size << std::endl;
				return false;
			}
		}
		else
		{
			out << "Can't file encoder for file " << fileInfo.name << std::endl;
			return false;
		}				
	}

	return true;
}