int CLuaInstFileHelpers::FileHelpersMkdir(lua_State *L) { CLuaFileHelpers *D = FileHelpersCheckData(L, 1); if (!D) return 0; int numargs = lua_gettop(L) - 1; int min_numargs = 1; if (numargs < min_numargs) { printf("luascript mkdir: not enough arguments (%d, expected %d)\n", numargs, min_numargs); lua_pushboolean(L, false); return 1; } if (!lua_isstring(L, 2)) { printf("%s: argument 1 is not a string.\n",__func__); lua_pushboolean(L, false); return 1; } const char *dir = luaL_checkstring(L, 2); mode_t mode = 0755; if (numargs > min_numargs) { int mode_i = luaL_checkint(L, 3); /* Hack for convert lua number to octal */ std::string mode_s = itoa(mode_i, 10); mode = (mode_t)(strtol(mode_s.c_str(), (char **)NULL, 8) & 0x0FFF); //printf("\n##### [%s:%d] str: %s, okt: %o \n \n", __func__, __LINE__, mode_s.c_str(), (int)mode); } bool ret = false; CFileHelpers* fh = CFileHelpers::getInstance(); fh->setConsoleQuiet(true); ret = fh->createDir(dir, mode); if (ret == false) { helpersDebugInfo di; fh->readDebugInfo(&di); lua_Debug ar; lua_getstack(L, 1, &ar); lua_getinfo(L, "Sl", &ar); printf(">>> Lua script error [%s:%d] %s\n (error from neutrino: [%s:%d])\n", ar.short_src, ar.currentline, di.msg.c_str(), di.file.c_str(), di.line); } lua_pushboolean(L, ret); return 1; }
bool COPKGManager::checkSize(const string& pkg_name) { string pkg_file = pkg_name; string plain_pkg = getBaseName(pkg_file); //exit check size if package already installed, because of auto remove of old stuff during installation if (isInstalled(plain_pkg)) return true; /* this is pretty broken right now for several reasons: * space in /tmp is limited (/tmp being ramfs usually, but wasted by unpacking the archive and then untaring it instead of using a pipe * the file is downloaded for this test, then discarded and later downloaded again for installation so until a better solution is found, simply disable it. */ #if 0 //get available root fs size //TODO: Check writability! struct statfs root_fs; statfs("/", &root_fs); u_int64_t free_size = root_fs.f_bfree*root_fs.f_bsize; /* * To calculate the required size for installation here we make a quasi-dry run, * it is a bit awkward, but relatively specific, other solutions are welcome. * We create a temporary test directory and fill it with downloaded or user uploaded package file. * Then we unpack the package and change into temporary testing directory. * The required size results from the size of generated folders and subfolders. * TODO: size of dependencies are not really considered */ CFileHelpers fh; //create test pkg dir string tmp_dest = OPKG_TEST_DIR; tmp_dest += "/package"; fh.createDir(tmp_dest); //change into test dir chdir(OPKG_TEST_DIR); //copy package into test dir string tmp_dest_file = OPKG_TEST_DIR; tmp_dest_file += "/" + plain_pkg; if(!access( pkg_file.c_str(), F_OK)) //use local package fh.copyFile(pkg_file.c_str(), tmp_dest_file.c_str(), 0644); else execCmd(pkg_types[OM_DOWNLOAD] + plain_pkg); //download package //unpack package into test dir string ar = "ar -x " + plain_pkg + char(0x2a); execCmd(ar); //untar package into test directory string untar_tar_cmd = "tar -xf "; untar_tar_cmd += OPKG_TEST_DIR; untar_tar_cmd += "/data.tar.gz -C " + tmp_dest; execCmd(untar_tar_cmd); //get new current required minimal size from dry run test dir u_int64_t req_size = fh.getDirSize(tmp_dest); //clean up fh.removeDir(OPKG_TEST_DIR); dprintf(DEBUG_INFO, "[COPKGManager] [%s - %d] Package: %s [required size=%" PRId64 " (free size: %" PRId64 ")]\n", __func__, __LINE__, pkg_name.c_str(), req_size, free_size); if (free_size < req_size){ //exit if required size too much dprintf(DEBUG_NORMAL, "[COPKGManager] [%s - %d] WARNING: size check freesize=%" PRId64 " (recommended: %" PRId64 ")\n", __func__, __LINE__, free_size, req_size); return false; } #endif return true; }
CFSMounter::MountRes CFSMounter::mount(const std::string &ip, const std::string &dir, const std::string &local_dir, const FSType fstype, const std::string &username, const std::string &password, std::string options1, std::string options2) { std::string cmd; pthread_mutex_init(&g_mut, NULL); pthread_cond_init(&g_cond, NULL); g_mntstatus=-1; FS_Support sup = fsSupported(fstype, true); /* keep modules if necessary */ if (sup == CFSMounter::FS_UNSUPPORTED) { printf("[CFSMounter] FS type %d not supported\n", (int) fstype); return MRES_FS_NOT_SUPPORTED; } printf("[CFSMounter] Mount(%d) %s:%s -> %s\n", (int) fstype, ip.c_str(), dir.c_str(), local_dir.c_str()); CFileHelpers fh; fh.createDir(local_dir.c_str(), 0755); if (isMounted(local_dir)) { printf("[CFSMounter] FS mount error %s already mounted\n", local_dir.c_str()); return MRES_FS_ALREADY_MOUNTED; } if(options1.empty()) { options1 = options2; options2 = ""; } if(options1.empty() && options2.empty()) { if(fstype == NFS) { options1 = "ro,soft,udp"; options2 = "nolock,rsize=8192,wsize=8192"; } else if(fstype == CIFS) { options1 = "ro"; options2 = ""; } else if(fstype == LUFS) { options1 = ""; options2 = ""; } } if(fstype == NFS) { cmd = "mount -t nfs "; cmd += ip; cmd += ':'; cmd += dir; cmd += ' '; cmd += local_dir; cmd += " -o "; cmd += options1; } else if(fstype == CIFS) { cmd = "mount -t cifs //"; cmd += ip; cmd += '/'; cmd += dir; cmd += ' '; cmd += local_dir; cmd += " -o username="******",password="******",iocharset=UTF8"; //cmd += ",unc=//"; for whats needed? //cmd += ip; //cmd += '/'; //cmd += dir; //cmd += ','; //cmd += options1; } else { cmd = "lufsd none "; cmd += local_dir; cmd += " -o fs=ftpfs,username="******",password="******",host="; cmd += ip; cmd += ",root=/"; cmd += dir; cmd += ','; cmd += options1; } if (options2[0] !='\0') { cmd += ','; cmd += options2; } pthread_create(&g_mnt, 0, mount_thread, (void *) cmd.c_str()); struct timespec timeout; int retcode; pthread_mutex_lock(&g_mut); timeout.tv_sec = time(NULL) + 5; timeout.tv_nsec = 0; retcode = pthread_cond_timedwait(&g_cond, &g_mut, &timeout); if (retcode == ETIMEDOUT) { // timeout occurred pthread_cancel(g_mnt); } pthread_mutex_unlock(&g_mut); pthread_join(g_mnt, NULL); if ( g_mntstatus != 0 ) { printf("[CFSMounter] FS mount error: \"%s\"\n", cmd.c_str()); return (retcode == ETIMEDOUT) ? MRES_TIMEOUT : MRES_UNKNOWN; } return MRES_OK; }