mirror of
https://github.com/sparkfun/OpenLog.git
synced 2024-09-20 00:50:14 +00:00
Added feature: no new file if old file is zero bytes.
See issue #136. Thank you dlkeng! You rock. Again. Thanks for adding this feature. When starting in new log mode, if the LOG00256.txt is zero bytes, OpenLog will use LOG00256 instead of LOG00257.
This commit is contained in:
parent
3fe82cfb40
commit
45960c3d21
@ -428,17 +428,29 @@ char* newlog(void)
|
||||
char new_file_name[13];
|
||||
while(1)
|
||||
{
|
||||
sprintf_P(new_file_name, PSTR("LOG%05d.TXT"), new_file_number); //Splice the new file number into this file name
|
||||
|
||||
//Try to open file, if fail (file doesn't exist), then break
|
||||
if (newFile.open(¤tDirectory, new_file_name, O_CREAT | O_EXCL | O_WRITE)) break;
|
||||
|
||||
//Try to open file and see if it is empty. If so, use it.
|
||||
if (newFile.open(¤tDirectory, new_file_name, O_READ))
|
||||
{
|
||||
if (newFile.fileSize() == 0)
|
||||
{
|
||||
newFile.close(); // Close this existing file we just opened.
|
||||
return(new_file_name); // Use existing empty file.
|
||||
}
|
||||
newFile.close(); // Close this existing file we just opened.
|
||||
}
|
||||
|
||||
//Try the next number
|
||||
new_file_number++;
|
||||
if(new_file_number > 65533) //There is a max of 65534 logs
|
||||
{
|
||||
NewSerial.print(F("!Too many logs:2!"));
|
||||
return(0); //Bail!
|
||||
}
|
||||
|
||||
sprintf_P(new_file_name, PSTR("LOG%05d.TXT"), new_file_number); //Splice the new file number into this file name
|
||||
|
||||
//Try to open file, if fail (file doesn't exist), then break
|
||||
if (newFile.open(¤tDirectory, new_file_name, O_CREAT | O_EXCL | O_WRITE)) break;
|
||||
}
|
||||
newFile.close(); //Close this new file we just opened
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user