aleskva
aleskva

Reputation: 1805

Directory comparison not working in Dart?

Why directory comparison does not work the expected way in Dart?

import 'dart:io';

void main() {
  Directory d = Directory('/kek');
  Directory e = Directory('/kek');
  print(d==e);  // false
  print(d.hashCode);  // 123456
  print(e.hashCode);  // 654321
}

Upvotes: 0

Views: 230

Answers (1)

Lee Daniel Crocker
Lee Daniel Crocker

Reputation: 13171

As I read the documentation for the Directory object, the hashCode and operator== methods are simply inherited from Object, and thus have no special implementation that would cause two different Directory objects to compare equal if they point to the same place.

This would be difficult to implement. Should the hashCode canonicalize relative paths and paths containing "." and ".."? Should it follow symlinks? What about files with multiple hard links?

Upvotes: 2

Related Questions