Skip to content

Commit

Permalink
Fix/extension deletion (#160)
Browse files Browse the repository at this point in the history
- fixed the deletion of extensions when there are several of them in the same directory
- fixed the deletion of hidden files on windows
  • Loading branch information
dnzbk authored Feb 8, 2024
1 parent 7c44eca commit 6501870
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
20 changes: 17 additions & 3 deletions daemon/extension/ExtensionManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,10 +188,24 @@ namespace ExtensionManager
{
const char* location = ext.GetLocation();

CString err;
if (FileSystem::DirectoryExists(location) && FileSystem::DeleteDirectoryWithContent(location, err))
ptrdiff_t count = std::count_if(
std::cbegin(m_extensions),
std::cend(m_extensions),
[&location](const auto& ext) { return strcmp(location, ext->GetLocation()) == 0; }
);

if (count > 1)
{
// for backward compatibility, when multiple V1 extensions placed
// in the same directory in which case we have to delete an entry file,
// not the entire directory.
location = ext.GetEntry();
}

if (FileSystem::DirectoryExists(location))
{
if (!err.Empty())
CString err;
if (!FileSystem::DeleteDirectoryWithContent(location, err))
{
return boost::optional<std::string>(err.Str());
}
Expand Down
1 change: 1 addition & 0 deletions daemon/util/FileSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,7 @@ bool FileSystem::CopyFile(const char* srcFilename, const char* dstFilename)
bool FileSystem::DeleteFile(const char* filename)
{
#ifdef WIN32
SetFileAttributes(filename, FILE_ATTRIBUTE_NORMAL);
return _wremove(UtfPathToWidePath(filename)) == 0;
#else
return remove(filename) == 0;
Expand Down

0 comments on commit 6501870

Please sign in to comment.