Skip to content

Commit

Permalink
Video Gallery: Remove directory structures, e.g. DVD folder
Browse files Browse the repository at this point in the history
The functionality introduced in commit 0d21b2b is not changed
but the implementation now uses the already existing function MythRemoveDirectory to do the
deletion, replacing the local implementations of removeDir.
Thanks to linuxdude42 for pointing out this optimization possibility.

Refs #176
  • Loading branch information
kmdewaal committed Jan 28, 2023
1 parent 5ece411 commit 53fa474
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 70 deletions.
48 changes: 10 additions & 38 deletions mythtv/libs/libmythprotoserver/requesthandler/deletethread.cpp
Expand Up @@ -85,35 +85,6 @@ bool DeleteThread::AddFile(DeleteHandler *handler)
return true;
}

bool DeleteThread::removeDir(const QString &dirname)
{
QDir dir(dirname);

if (!dir.exists())
return false;

dir.setFilter(QDir::Files | QDir::Dirs | QDir::NoDotAndDotDot);
QFileInfoList list = dir.entryInfoList();
QFileInfoList::const_iterator it = list.begin();
const QFileInfo *fi;

while (it != list.end())
{
fi = &(*it++);
if (fi->isFile() && !fi->isSymLink())
{
QFile::remove(fi->absoluteFilePath());
}
else if (fi->isDir() && !fi->isSymLink())
{
if(!removeDir(fi->absoluteFilePath())) return false;
}
}

dir.rmdir(dirname);
return true;
}

void DeleteThread::ProcessNew(void)
{
// loop through new files, unlinking and adding for deletion
Expand Down Expand Up @@ -200,15 +171,16 @@ void DeleteThread::ProcessNew(void)
{
LOG(VB_FILE, LOG_INFO, QString("About to unlink/delete file"));

if(!removeDir(cpath))
{
LOG(VB_GENERAL, LOG_ERR,
QString("Error deleting '%1': is no directory ")
.arg(cpath) + ENO);
handler->DeleteFailed();
handler->DecrRef();
continue;
}
QDir dir(cpath);
if(MythRemoveDirectory(dir))
{
LOG(VB_GENERAL, LOG_ERR,
QString("Error deleting '%1': is no directory ")
.arg(cpath) + ENO);
handler->DeleteFailed();
handler->DecrRef();
continue;
}
}
// unlink the file so as soon as it is closed, the system will
// delete it from the filesystem
Expand Down
Expand Up @@ -27,7 +27,6 @@ class DeleteThread : public QObject, public MThread
void Stop(void) { m_run = false; }

private:
bool removeDir(const QString &dirname);
void ProcessNew(void);
void ProcessOld(void);

Expand Down
32 changes: 2 additions & 30 deletions mythtv/programs/mythbackend/mainserver.cpp
Expand Up @@ -2659,35 +2659,6 @@ void MainServer::DoDeleteInDB(DeleteStruct *ds)
}
}

bool MainServer::removeDir(const QString &dirname)
{
QDir dir(dirname);

if (!dir.exists())
return false;

dir.setFilter(QDir::Files | QDir::Dirs | QDir::NoDotAndDotDot);
QFileInfoList list = dir.entryInfoList();
QFileInfoList::const_iterator it = list.begin();
const QFileInfo *fi;

while (it != list.end())
{
fi = &(*it++);
if (fi->isFile() && !fi->isSymLink())
{
QFile::remove(fi->absoluteFilePath());
}
else if (fi->isDir() && !fi->isSymLink())
{
if(!removeDir(fi->absoluteFilePath())) return false;
}
}

dir.rmdir(dirname);
return true;
}

/**
* \brief Deletes links and unlinks the main file and returns the descriptor.
*
Expand Down Expand Up @@ -2764,7 +2735,8 @@ int MainServer::OpenAndUnlink(const QString &filename)
{
if (errno == EISDIR)
{
if(!removeDir(filename))
QDir dir(filename);
if(MythRemoveDirectory(dir))
{
LOG(VB_GENERAL, LOG_ERR, msg + " could not delete directory " + ENO);
return -1;
Expand Down
1 change: 0 additions & 1 deletion mythtv/programs/mythbackend/mainserver.h
Expand Up @@ -302,7 +302,6 @@ class MainServer : public QObject, public MythSocketCBs

void SetExitCode(int exitCode, bool closeApplication);

static bool removeDir(const QString &dirname);
static int DeleteFile(const QString &filename, bool followLinks,
bool deleteBrokenSymlinks = false);
static int OpenAndUnlink(const QString &filename);
Expand Down

0 comments on commit 53fa474

Please sign in to comment.