this->nextGid_ = VFS_GID_START;
this->noSync_ = false;
+ this->dirtyUsers_ = false;
+ this->dirtyGroups_ = false;
vfsReload();
}
VfsAuthn::~VfsAuthn()
{
+ if (dirtyUsers_) vfsSaveUsers();
+ if (dirtyGroups_) vfsSaveGroups();
}
// bulk update
this->noSync_ = false;
- if (ngroups != this->groups_.size())
+ if (ngroups != this->groups_.size() || this->dirtyGroups_)
vfsSaveGroups();
}
this->groups_.push_back(gi);
this->gids_.insert(gid);
this->nextGid_ = gid + 1;
+ this->dirtyGroups_ = true;
debug("new group '%s', gid %d", groupName.c_str(), gid);
}
this->users_.push_back(ui);
this->uids_.insert(uid);
this->nextUid_ = uid + 1;
+ this->dirtyUsers_ = true;
debug("new user '%s', uid %d", userName.c_str(), uid);
}
this->groups_.erase(this->groups_.begin() + i);
this->gids_.erase(gid);
//not needed immediately: if (this->nextGid_ > gid) this->nextGid_ = gid;
+ this->dirtyGroups_ = true;
vfsSaveGroups();
}
this->users_.erase(this->users_.begin() + i);
this->uids_.erase(uid);
//not needed immediately: if (this->nextUid_ > uid) this->nextUid_ = uid;
+ this->dirtyUsers_ = true;
vfsSaveUsers();
}
std::ofstream f;
std::string newName, name;
- if (this->noSync_) return;
+ if (this->noSync_) {
+ this->dirtyUsers_ = true;
+ return;
+ }
name = this->prefix_ + VFS_USERS_FILE;
newName = this->prefix_ + ".new" + VFS_USERS_FILE;
f.open(newName.c_str());
- if (!f)
- vfsThrow(EIO, "could not create new version of users file");
+ if (!f) {
+ log(LOG_NOTICE, "could not create new version of users file in '%s'", this->prefix_.c_str());
+ this->dirtyUsers_ = true;
+ return;
+ }
for (size_t i = 0; i < this->users_.size(); i++) {
f << this->users_[i].getUnsigned("uid") << "\t";
f.close();
wrapCall(rename(newName.c_str(), name.c_str()), "could not save users file");
+
+ this->dirtyUsers_ = false;
}
std::ofstream f;
std::string newName, name;
- if (this->noSync_) return;
+ if (this->noSync_) {
+ this->dirtyGroups_ = true;
+ return;
+ }
name = this->prefix_ + VFS_GROUPS_FILE;
newName = this->prefix_ + ".new" + VFS_GROUPS_FILE;
f.open(newName.c_str());
- if (!f)
- vfsThrow(EIO, "could not create new version of groups file");
+ if (!f) {
+ log(LOG_NOTICE, "could not create new version of groups file in '%s'", this->prefix_.c_str());
+ this->dirtyGroups_ = true;
+ return;
+ }
for (size_t i = 0; i < this->groups_.size(); i++) {
f << this->groups_[i].getUnsigned("gid") << "\t";
f.close();
wrapCall(rename(newName.c_str(), name.c_str()), "could not save groups file");
+
+ this->dirtyGroups_ = false;
}