Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Video Gallery: Remove directory structures, e.g. DVD folder
The Video Gallery correctly recognizes and handles DVD folders (Video_TS structure) but it can not be deleted from within Mythfrontend. This commit adds the functionality that when pressing delete in the menu the whole DVD folder is deleted. Thanks to Lomion0815 for contributing this fix. Refs #176
- Loading branch information
Showing
4 changed files
with
87 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2659,6 +2659,35 @@ 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; | ||
} | ||
|
||
This comment has been minimized.
Sorry, something went wrong.
linuxdude42
Contributor
|
||
/** | ||
* \brief Deletes links and unlinks the main file and returns the descriptor. | ||
* | ||
|
@@ -2710,7 +2739,7 @@ int MainServer::DeleteFile(const QString &filename, bool followLinks, | |
return -2; // valid result, not an error condition | ||
} | ||
|
||
if (fd < 0) | ||
if (fd < 0 && errno != EISDIR) | ||
LOG(VB_GENERAL, LOG_ERR, LOC + errmsg + ENO); | ||
|
||
return fd; | ||
|
@@ -2733,11 +2762,21 @@ int MainServer::OpenAndUnlink(const QString &filename) | |
|
||
if (fd == -1) | ||
{ | ||
LOG(VB_GENERAL, LOG_ERR, LOC + msg + " could not open " + ENO); | ||
return -1; | ||
if (errno == EISDIR) | ||
{ | ||
if(!removeDir(filename)) | ||
{ | ||
LOG(VB_GENERAL, LOG_ERR, msg + " could not delete directory " + ENO); | ||
return -1; | ||
} | ||
} | ||
else | ||
{ | ||
LOG(VB_GENERAL, LOG_ERR, msg + " could not open " + ENO); | ||
return -1; | ||
} | ||
} | ||
|
||
if (unlink(fname.constData())) | ||
else if (unlink(fname.constData())) | ||
{ | ||
LOG(VB_GENERAL, LOG_ERR, LOC + msg + " could not unlink " + ENO); | ||
close(fd); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 comment
on commit 0d21b2b
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi David, thanks for your comments. I will have a look at it.
This appears to duplicate the functionality of MythRemoveDirectory from libmythbase/mythmiscutil.cpp.