Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix fileAddDate with SIGUSR1 #200

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 8 additions & 50 deletions darkice/trunk/src/DarkIce.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -345,27 +345,16 @@ DarkIce :: configIceCast ( const Config & config,

// check for and create the local dump file if needed
if ( localDumpName != 0 ) {
if ( fileAddDate ) {
if (fileDateFormat == 0) {
localDumpName = Util::fileAddDate(localDumpName);
}
else {
localDumpName = Util::fileAddDate( localDumpName,
fileDateFormat );
}
}
localDumpFile = new FileSink( stream, localDumpName,
fileAddDate, fileDateFormat );

localDumpFile = new FileSink( stream, localDumpName);
if ( !localDumpFile->exists() ) {
if ( !localDumpFile->create() ) {
reportEvent( 1, "can't create local dump file",
localDumpName);
localDumpFile = 0;
}
}
if ( fileAddDate ) {
delete[] localDumpName;
}
}
// streaming related stuff
audioOuts[u].socket = new TcpSocket( server, port);
Expand Down Expand Up @@ -575,27 +564,15 @@ DarkIce :: configIceCast2 ( const Config & config,

// check for and create the local dump file if needed
if ( localDumpName != 0 ) {
if ( fileAddDate ) {
if (fileDateFormat == 0) {
localDumpName = Util::fileAddDate(localDumpName);
}
else {
localDumpName = Util::fileAddDate( localDumpName,
fileDateFormat );
}
}

localDumpFile = new FileSink( stream, localDumpName);
localDumpFile = new FileSink( stream, localDumpName,
fileAddDate, fileDateFormat );
if ( !localDumpFile->exists() ) {
if ( !localDumpFile->create() ) {
reportEvent( 1, "can't create local dump file",
localDumpName);
localDumpFile = 0;
}
}
if ( fileAddDate ) {
delete[] localDumpName;
}
}

// streaming related stuff
Expand Down Expand Up @@ -902,27 +879,16 @@ DarkIce :: configShoutCast ( const Config & config,

// check for and create the local dump file if needed
if ( localDumpName != 0 ) {
if ( fileAddDate ) {
if (fileDateFormat == 0) {
localDumpName = Util::fileAddDate(localDumpName);
}
else {
localDumpName = Util::fileAddDate( localDumpName,
fileDateFormat );
}
}
localDumpFile = new FileSink( stream, localDumpName,
fileAddDate, fileDateFormat );

localDumpFile = new FileSink( stream, localDumpName);
if ( !localDumpFile->exists() ) {
if ( !localDumpFile->create() ) {
reportEvent( 1, "can't create local dump file",
localDumpName);
localDumpFile = 0;
}
}
if ( fileAddDate ) {
delete[] localDumpName;
}
}

// streaming related stuff
Expand Down Expand Up @@ -1074,17 +1040,9 @@ DarkIce :: configFileCast ( const Config & config )
// go on and create the things

// the underlying file
if ( fileAddDate ) {
if (fileDateFormat == 0) {
targetFileName = Util::fileAddDate( targetFileName);
}
else {
targetFileName = Util::fileAddDate( targetFileName,
fileDateFormat );
}
}
FileSink * targetFile = new FileSink( stream, targetFileName,
fileAddDate, fileDateFormat );

FileSink * targetFile = new FileSink( stream, targetFileName);
if ( !targetFile->exists() ) {
if ( !targetFile->create() ) {
throw Exception( __FILE__, __LINE__,
Expand Down
44 changes: 36 additions & 8 deletions darkice/trunk/src/FileSink.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,18 @@ static const char fileid[] = "$Id$";
*----------------------------------------------------------------------------*/
void
FileSink :: init ( const char * configName,
const char * name )
const char * name,
const bool nameAddDate,
const char * fileDateFormat )
{
this->configName = Util::strDup(configName);
fileName = Util::strDup(name);
addDate = nameAddDate;
if (fileDateFormat) {
this->fileDateFormat = Util::strDup(fileDateFormat);
}
fileDescriptor = 0;
fileNameActual = 0;
}


Expand All @@ -138,6 +145,9 @@ FileSink :: strip ( void)
}

delete[] fileName;
delete[] fileNameActual;
if (fileDateFormat)
delete[] fileDateFormat;
}


Expand All @@ -149,7 +159,7 @@ FileSink :: FileSink ( const FileSink & fs )
{
int fd;

init( fs.configName, fs.fileName);
init( fs.configName, fs.fileName, fs.addDate, fs.fileDateFormat);

if ( (fd = fs.fileDescriptor ? dup( fs.fileDescriptor) : 0) == -1 ) {
strip();
Expand All @@ -176,7 +186,7 @@ FileSink :: operator= ( const FileSink & fs )
/* then build up */
Sink::operator=( fs );

init( fs.configName, fs.fileName);
init( fs.configName, fs.fileName, fs.addDate, fs.fileDateFormat);

if ( (fd = fs.fileDescriptor ? dup( fs.fileDescriptor) : 0) == -1 ) {
strip();
Expand Down Expand Up @@ -220,8 +230,26 @@ FileSink :: create ( void )
/* filemode default to 0666 */
const int filemode = (S_IRUSR|S_IWUSR|S_IWGRP|S_IRGRP|S_IROTH|S_IWOTH) ;
/* create the file */
if ( (fd = ::creat( fileName, filemode )) == -1 ) {
reportEvent( 3, "can't create file", fileName, errno);
if (fileNameActual != 0) {
delete[] fileNameActual;
}

if ( addDate ) {
if (fileDateFormat == 0) {
fileNameActual = Util::fileAddDate(fileName);
}
else {
fileNameActual = Util::fileAddDate( fileName,
fileDateFormat );
}
}
else {
fileNameActual = Util::strDup(fileName);
}


if ( (fd = ::creat( fileNameActual, filemode)) == -1 ) {
reportEvent( 3, "can't create file", fileNameActual, errno);
return false;
}

Expand All @@ -240,7 +268,7 @@ FileSink :: open ( void )
return false;
}

if ( (fileDescriptor = ::open( fileName, O_WRONLY | O_TRUNC, 0)) == -1 ) {
if ( (fileDescriptor = ::open( fileNameActual, O_WRONLY | O_TRUNC, 0)) == -1 ) {
fileDescriptor = 0;
return false;
}
Expand Down Expand Up @@ -352,8 +380,8 @@ FileSink :: cut ( void ) throw ()
try {
std::string archiveFileName = getArchiveFileName();

if (::rename(fileName, archiveFileName.c_str()) != 0) {
reportEvent(2, "couldn't move file", fileName,
if (::rename(fileNameActual, archiveFileName.c_str()) != 0) {
reportEvent(2, "couldn't move file", fileNameActual,
"to", archiveFileName);
}

Expand Down
30 changes: 27 additions & 3 deletions darkice/trunk/src/FileSink.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,15 @@ class FileSink : public Sink, public virtual Reporter
* @param configName the name of the configuration related to
* this file sink. something like "file-0" or "file-2".
* @param name name of the file to be represented by the object.
* @param addDate add a date to the filename.
* @param fileDateFormat optional date format of the added date
* @exception Exception
*/
void
init ( const char * configName,
const char * name ) ;
const char * name,
const bool addDate,
const char * fileDateFormat );

/**
* De-initialize the object.
Expand Down Expand Up @@ -108,6 +112,22 @@ class FileSink : public Sink, public virtual Reporter
int fileDescriptor;

/**
* Actual filename f.e. when using fileAddDate.
*/
char * fileNameActual;

/**
* Whether a date is added to the filename or not.
*/
bool addDate;

/**
* Date format of the added date.
*/
char * fileDateFormat;

/**

* Default constructor. Always throws an Exception.
*
* @exception Exception
Expand All @@ -127,13 +147,17 @@ class FileSink : public Sink, public virtual Reporter
* @param configName the name of the configuration related to
* this file sink. something like "file-0" or "file-2".
* @param name name of the file to be represented by the object.
* @param addDate add a date to the filename.
* @param fileDateFormat optional date format of the added date
* @exception Exception
*/
inline
FileSink( const char * configName,
const char * name )
const char * name,
const bool addDate,
const char * fileDateFormat )
{
init( configName, name);
init( configName, name, addDate, fileDateFormat );
}

/**
Expand Down