aria2/test/TestUtil.cc
Tatsuhiro Tsujikawa dbc8f5b737 2008-09-07 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Implemented the ability to get timestamp from remote HTTP server 
and
	apply it to local file. To enable this feature, --remote-time 
option
	is added. No usage text has been written yet.
	If several servers returns difference timestamp, then aria2 uses 
latest
	one.
	* src/CopyDiskAdaptor.cc
	* src/CopyDiskAdaptor.h
	* src/DirectDiskAdaptor.cc
	* src/DirectDiskAdaptor.h
	* src/DiskAdaptor.h
	* src/File.cc
	* src/File.h
	* src/HttpHeader.cc
	* src/HttpHeader.h
	* src/HttpResponse.cc
	* src/HttpResponse.h
	* src/HttpResponseCommand.cc
	* src/HttpResponseCommand.h
	* src/MultiDiskAdaptor.cc
	* src/MultiDiskAdaptor.h
	* src/OptionHandlerFactory.cc
	* src/RequestGroup.cc
	* src/RequestGroup.h
	* src/RequestGroupMan.cc
	* src/option_processing.cc
	* src/prefs.cc
	* src/prefs.h
	* test/CopyDiskAdaptorTest.cc
	* test/FileTest.cc
	* test/Makefile.am
	* test/Makefile.in
	* test/MultiDiskAdaptorTest.cc
	* test/TestUtil.cc
2008-09-07 14:38:26 +00:00

29 lines
684 B
C++

#include "TestUtil.h"
#include "a2io.h"
#include "File.h"
#include "StringFormat.h"
#include "FatalException.h"
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <cerrno>
#include <cstring>
namespace aria2 {
void createFile(const std::string& path, size_t length)
{
File(File(path).getDirname()).mkdirs();
int fd = creat(path.c_str(), OPEN_MODE);
if(fd == -1) {
throw FatalException(StringFormat("Could not create file=%s. cause:%s",
path.c_str(), strerror(errno)).str());
}
if(-1 == ftruncate(fd, length)) {
throw FatalException(StringFormat("ftruncate failed. cause:%s",
strerror(errno)).str());
}
close(fd);
}
};