Skip to content

SizeRollingFileTree problem #123

@joyhope

Description

@joyhope

I meet the problem: the first log is always deleted when sizerollingfile tree is used. I dig the problem.

The problem code
void detectFileIndex() { var rootDir = Directory(filenamePrefix); <<== this is wrong, because it is not directory, it is prefix patten. if (!rootDir.existsSync()) { /// no files created yet. _fileIndex = 0; rollToNextFile(); return; } if (filenamePrefix.contains(Platform.pathSeparator)) { rootDir = Directory(filenamePrefix.substring( 0, filenamePrefix.lastIndexOf(Platform.pathSeparator))); } var logListIndexes = rootDir .listSync() .map((fe) => getLogIndex(fe.path)) .where((i) => i >= 0) .toList(); logListIndexes.sort();

I try to fix it.
` void detectFileIndex() {
var rootDir;

if (filenamePrefix.contains(Platform.pathSeparator)) {  <<== changed
} else {
  rootDir = Directory(filenamePrefix);
  if (!rootDir.existsSync()) {
    /// no files created yet.
    _fileIndex = 0;
    rollToNextFile();
    return;
  }
}

rootDir = Directory(filenamePrefix.substring(
    0, filenamePrefix.lastIndexOf(Platform.pathSeparator)));

var logListIndexes = rootDir
    .listSync()
    .map((fe) => getLogIndex(fe.path))
    .where((i) => (i >= 0) as bool)   <<==changed, otherwise the runtime exception happen,
    .toList();
logListIndexes.sort();

`

After the fix, it seems to work as expected.

Could you review and make update?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions