Fix problem with opening multiple empty files on FAT file systems

The problem is that empty files on a FAT file system all have the same inode so TextMate would consider them to be links of each other and only show the last one opened.

Fixes #979.
This commit is contained in:
Allan Odgaard
2013-05-15 16:14:07 +07:00
parent 0795b89bdb
commit 7f88fcbdf3
2 changed files with 21 additions and 3 deletions

View File

@@ -397,6 +397,18 @@ namespace path
}
}
bool identifier_t::can_trust_inode () const
{
if(exists && inode == 999999999) // Zero-length files on FAT file systems share this magic value
{
struct statfs sfsb;
if(statfs(path.c_str(), &sfsb) == 0)
return strcasecmp(sfsb.f_fstypename, "msdos") == 0 && strcasecmp(sfsb.f_fstypename, "exfat") == 0;
perror("statfs");
}
return true;
}
bool identifier_t::operator< (identifier_t const& rhs) const
{
if(path == rhs.path)
@@ -405,15 +417,20 @@ namespace path
if(exists == rhs.exists)
{
if(exists)
return device == rhs.device ? inode < rhs.inode : device < rhs.device;
else return path < rhs.path;
{
if(device != rhs.device)
return device < rhs.device;
else if(can_trust_inode() && rhs.can_trust_inode())
return inode < rhs.inode;
}
return path < rhs.path;
}
return !exists && rhs.exists;
}
bool identifier_t::operator== (identifier_t const& rhs) const
{
return path == rhs.path || (exists && rhs.exists && device == rhs.device && inode == rhs.inode);
return path == rhs.path || (exists && rhs.exists && device == rhs.device && inode == rhs.inode && can_trust_inode());
}
bool identifier_t::operator!= (identifier_t const& rhs) const

View File

@@ -42,6 +42,7 @@ namespace path
bool operator!= (identifier_t const& rhs) const;
explicit operator bool () const { return exists || path != NULL_STR; }
private:
bool can_trust_inode () const;
bool exists;
dev_t device;
ino_t inode;