Skip to content

Commit

Permalink
Load old style index files.
Browse files Browse the repository at this point in the history
  • Loading branch information
weetmuts committed Mar 15, 2024
1 parent 7a46137 commit 737d462
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
22 changes: 16 additions & 6 deletions src/tarfile.cc
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,7 @@ bool TarFileName::parseFileName(string &name, string *dir)

bool TarFileName::parseFileNameVersion_(string &name, size_t p1)
{
// old style beak_z_1597335691.456088_4626d1b74c82f446e1ab01f746b10b83bbfcf33ee6f56f9fd5978f5df0d55033_1-1_1536_2000.gz
// beak_z_1597335691.456088.2024-01-13.1232_4626d1b74c82f446e1ab01f746b10b83bbfcf33ee6f56f9fd5978f5df0d55033_1-1_1536_2000.gz
bool k;
size_t p2 = name.find('.', p1+1); if (p2 == string::npos) return false;
Expand All @@ -305,7 +306,11 @@ bool TarFileName::parseFileNameVersion_(string &name, size_t p1)
if (len < 6) return false;
k = digitsOnly(&name[p2+1], 6, &usecss);
if (!k) return false;
if (len == 22)
if (len == 6)
{
old_style = true;
}
else
{
// Check the contents of the date string as well.
}
Expand Down Expand Up @@ -362,21 +367,26 @@ void TarFileName::writeTarFileNameIntoBufferVersion_(char *buf, size_t buf_len,
long usec = nsec/1000;
snprintf(secs_and_micros, 32, "%" PRINTF_TIME_T "u.%06lu", sec, usec);

char date_time[18];
// YYYY-MM-DD.HHMMSS
char date_time[20];
// .YYYY-MM-DD.HHMMSS
memset(date_time, 0, sizeof(date_time));
struct tm tmp;
memset(&tmp, 0, sizeof(tmp));
gmtime_r(&sec, &tmp);
strftime(date_time, 18, "%Y-%m-%d.%H%M%S", &tmp);
strftime(date_time, 20, ".%Y-%m-%d.%H%M%S", &tmp);

if (old_style)
{
date_time[0] = 0;
}

// Add 1 to part_nr, to make the index count from 1 in the file names.
string partnr = toHex(part_nr+1, num_parts);
const char *suffix = suffixtype(type);

if (dir == NULL)
{
snprintf(buf, buf_len, "beak_%c_%s.%s_%s_%s-%x_%s_%s.%s",
snprintf(buf, buf_len, "beak_%c_%s%s_%s_%s-%x_%s_%s.%s",
TarFileName::chartype(type),
secs_and_micros,
date_time,
Expand All @@ -390,7 +400,7 @@ void TarFileName::writeTarFileNameIntoBufferVersion_(char *buf, size_t buf_len,
else
{
const char *slashornot = dir->str().length() > 0 ? "/" : "";
snprintf(buf, buf_len, "%s%sbeak_%c_%s.%s_%s_%s-%x_%s_%s.%s",
snprintf(buf, buf_len, "%s%sbeak_%c_%s%s_%s_%s-%x_%s_%s.%s",
dir->c_str(),
slashornot,
TarFileName::chartype(type),
Expand Down
1 change: 1 addition & 0 deletions src/tarfile.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ struct TarFileName
std::string header_hash {};
uint part_nr {};
uint num_parts {};
bool old_style {}; // no human readable date time

TarFileName() : version(2) {};
TarFileName(const TarFileName&tfn) : type(tfn.type),
Expand Down

0 comments on commit 737d462

Please sign in to comment.