Ticket #2364: mythtv-stat_before_unlink.patch
File mythtv-stat_before_unlink.patch, 2.8 KB (added by , 18 years ago) |
---|
-
programs/mythbackend/mainserver.h
152 152 static int DeleteFile(const QString &filename, bool followLinks); 153 153 static int OpenAndUnlink(const QString &filename); 154 154 static bool TruncateAndClose(const AutoExpire *expirer, 155 int fd, const QString &filename); 155 int fd, const QString &filename, 156 off_t fsize); 156 157 157 158 QPtrList<LiveTVChain> liveTVChains; 158 159 QMutex liveTVChainsLock; -
programs/mythbackend/mainserver.cpp
1430 1430 bool followLinks = gContext->GetNumSetting("DeletesFollowLinks", 0); 1431 1431 bool slowDeletes = gContext->GetNumSetting("TruncateDeletesSlowly", 0); 1432 1432 int fd = -1; 1433 off_t size = 0; 1433 1434 bool errmsg = false; 1434 1435 1435 1436 /* Delete recording. */ 1436 1437 if (slowDeletes) 1437 1438 { 1439 // Since stat fails after unlinking on some filesystems, 1440 // get the filesize first 1441 struct stat st; 1442 if (stat(ds->filename, &st) == 0) 1443 size = st.st_size; 1438 1444 fd = DeleteFile(ds->filename, followLinks); 1439 1445 1440 1446 if ((fd < 0) && checkFile.exists()) … … 1482 1488 if (slowDeletes && fd != -1) 1483 1489 { 1484 1490 m_expirer->TruncatePending(); 1485 TruncateAndClose(m_expirer, fd, ds->filename );1491 TruncateAndClose(m_expirer, fd, ds->filename, size); 1486 1492 m_expirer->TruncateFinished(); 1487 1493 } 1488 1494 } … … 1638 1644 * is running at a time. 1639 1645 */ 1640 1646 bool MainServer::TruncateAndClose(const AutoExpire *expirer, 1641 int fd, const QString &filename) 1647 int fd, const QString &filename, 1648 off_t fsize) 1642 1649 { 1643 1650 QMutexLocker locker(&truncate_and_close_lock); 1644 1651 … … 1659 1666 .arg(increment / (1024.0 * 1024.0), 0, 'f', 2) 1660 1667 .arg(sleep_time)); 1661 1668 1662 // Get the on disk file size and preferred I/O block size.1663 struct stat buf;1664 fstat(fd, &buf);1665 // Estimate the file size. Don't use buf.st_blksize * buf.st_blocks1666 // The unit for st_blocks is undefined. See section "RATIONALE" at1667 // http://www.opengroup.org/onlinepubs/000095399/basedefs/sys/stat.h.html1668 off_t fsize = ((buf.st_size / buf.st_blksize) + 1) * buf.st_blksize;1669 1670 // Round truncate increment up to a blocksize, w/min of 1 block.1671 increment = ((increment / buf.st_blksize) + 1) * buf.st_blksize;1672 1673 1669 while (fsize > 0) 1674 1670 { 1675 1671 //VERBOSE(VB_FILE, QString("Truncating '%1' to %2 MB")