From e2437dd21c86f69840b7a513d10e973ff680f6b8 Mon Sep 17 00:00:00 2001 From: Michael Liebmann Date: Wed, 21 Aug 2013 01:19:03 +0200 Subject: [PATCH] Softupdate: Check the available space before copy image to /tmp on apollo Origin commit data ------------------ Branch: ni/coolstream Commit: https://github.com/neutrino-images/ni-neutrino/commit/8a5c32d0f6a9f314de4ae7e2a530e2d51a9ebfe6 Author: Michael Liebmann Date: 2013-08-21 (Wed, 21 Aug 2013) ------------------ No further description and justification available within origin commit message! ------------------ This commit was generated by Migit --- src/system/flashtool.cpp | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/src/system/flashtool.cpp b/src/system/flashtool.cpp index 1a57987f0..636269a5b 100644 --- a/src/system/flashtool.cpp +++ b/src/system/flashtool.cpp @@ -173,7 +173,25 @@ bool CFlashTool::program( const std::string & filename, int globalProgressEndEra strncpy(buf1, filename.c_str(), sizeof(buf1)-1); char* dn = dirname(buf1); std::string flashfile; + + bool skipCopy = false; +#ifdef BOXMODEL_APOLLO if (strcmp(dn, "/tmp") != 0) { + long btotal = 0, bused = 0, bsize = 0; + if (get_fs_usage("/tmp", btotal, bused, &bsize)) { + int fileSize = file_size(filename.c_str()) / 1024; + int backupMaxSize = (int)((btotal - bused) * bsize); + int res = 10; // Reserved 10% of available space + backupMaxSize = (backupMaxSize - ((backupMaxSize * res) / 100)) / 1024; + if (backupMaxSize < fileSize) + skipCopy = true; + } + else + skipCopy = true; + } +#endif + + if ((strcmp(dn, "/tmp") != 0) && !skipCopy) { memset(buf1, 0, sizeof(buf1)); strncpy(buf1, filename.c_str(), sizeof(buf1)-1); flashfile = (std::string)"/tmp/" + basename(buf1); @@ -190,8 +208,10 @@ bool CFlashTool::program( const std::string & filename, int globalProgressEndEra flashfile = filename; // Unmount all NFS & CIFS volumes - nfs_mounted_once = false; - CFSMounter::umount(); + if (!skipCopy) { + nfs_mounted_once = false; + CFSMounter::umount(); + } if( (fd1 = open( flashfile.c_str(), O_RDONLY )) < 0 ) { ErrorMessage = g_Locale->getText(LOCALE_FLASHUPDATE_CANTOPENFILE);