mirror of
https://github.com/GothenburgBitFactory/timewarrior.git
synced 2025-07-07 20:06:39 +02:00
Datafile: Exclusions inserted when not found in data
This commit is contained in:
parent
13da904da0
commit
779e0ce239
2 changed files with 25 additions and 14 deletions
|
@ -93,9 +93,6 @@ void Datafile::setExclusions (const std::vector <std::string>& exclusions)
|
||||||
// TODO _dirty = true;
|
// TODO _dirty = true;
|
||||||
|
|
||||||
_exclusions = exclusions;
|
_exclusions = exclusions;
|
||||||
|
|
||||||
for (auto& exclusion : _exclusions)
|
|
||||||
_lines.push_back (exclusion);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -151,7 +148,7 @@ void Datafile::commit ()
|
||||||
{
|
{
|
||||||
_file.lock ();
|
_file.lock ();
|
||||||
_file.truncate ();
|
_file.truncate ();
|
||||||
_file.append (std::string("")); // Seek to EOF.
|
_file.append (std::string ("")); // Seek to EOF.
|
||||||
|
|
||||||
// Write out all the lines.
|
// Write out all the lines.
|
||||||
for (auto& line : _lines)
|
for (auto& line : _lines)
|
||||||
|
@ -162,8 +159,6 @@ void Datafile::commit ()
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
throw format ("Could not write to data file {1}", _file._data);
|
throw format ("Could not write to data file {1}", _file._data);
|
||||||
|
|
||||||
_dirty = false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -189,9 +184,32 @@ void Datafile::load_lines ()
|
||||||
if (_file.open ())
|
if (_file.open ())
|
||||||
{
|
{
|
||||||
_file.lock ();
|
_file.lock ();
|
||||||
_file.read (_lines);
|
|
||||||
|
// File::read calls read_lines.clear (), so this prevents the exclsions from
|
||||||
|
// being discarded.
|
||||||
|
std::vector <std::string> read_lines;
|
||||||
|
_file.read (read_lines);
|
||||||
_file.close ();
|
_file.close ();
|
||||||
|
|
||||||
|
bool hasExclusions = false;
|
||||||
|
for (auto& line : read_lines)
|
||||||
|
{
|
||||||
|
if (line[0] == 'e')
|
||||||
|
{
|
||||||
|
hasExclusions = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add the exclusions to new files.
|
||||||
|
if (! hasExclusions)
|
||||||
|
for (auto& e : _exclusions)
|
||||||
|
_lines.push_back (e);
|
||||||
|
|
||||||
|
// Append the lines that were read.
|
||||||
|
for (auto& line : read_lines)
|
||||||
|
_lines.push_back (line);
|
||||||
|
|
||||||
_lines_loaded = true;
|
_lines_loaded = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,7 +46,6 @@ public:
|
||||||
void setExclusions (const std::vector <std::string>&);
|
void setExclusions (const std::vector <std::string>&);
|
||||||
void addInterval (const Interval&);
|
void addInterval (const Interval&);
|
||||||
void deleteInterval (const Interval&);
|
void deleteInterval (const Interval&);
|
||||||
|
|
||||||
void commit ();
|
void commit ();
|
||||||
|
|
||||||
std::string dump () const;
|
std::string dump () const;
|
||||||
|
@ -55,17 +54,11 @@ private:
|
||||||
void load_lines ();
|
void load_lines ();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// File representing data.
|
|
||||||
File _file {};
|
File _file {};
|
||||||
bool _dirty {false};
|
bool _dirty {false};
|
||||||
|
|
||||||
// Lines read from file, not parsed.
|
|
||||||
std::vector <std::string> _lines {};
|
std::vector <std::string> _lines {};
|
||||||
bool _lines_loaded {false};
|
bool _lines_loaded {false};
|
||||||
|
|
||||||
// Exclusions fed from Database.
|
|
||||||
std::vector <std::string> _exclusions {};
|
std::vector <std::string> _exclusions {};
|
||||||
|
|
||||||
Daterange _range {};
|
Daterange _range {};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue