diff --git a/fileSystem.c b/fileSystem.c index 8b18d18d65b4ccb8b42a7333c7abe01d8e81b077..f29aa7a346e51f2d0997221db07387c08eded9b0 100644 --- a/fileSystem.c +++ b/fileSystem.c @@ -30,7 +30,7 @@ int changeusrPath(MYSQL* mysql, char* usrPath, userProcess_t* puser){ else if(strcmp("..", dir) == 0){ //curid向前追溯一个 如果追溯的id为-1,则什么都不做 若不为-1,curid改为追溯的id char sql[1024]; - sprintf(sql, "select preid from dirsys where id = %d and tomb = 0 and user = '%s' and type = 'd';", puser1->curid, puser1->username); + sprintf(sql, "select preid from vfsystem where id = %d and tomb = 0 and user = '%s' and type = 'd';", puser1->curid, puser1->username); printf("%s\n", sql); int qret = mysql_query(mysql, sql); @@ -67,7 +67,7 @@ int changeusrPath(MYSQL* mysql, char* usrPath, userProcess_t* puser){ else{ //根据用户名、dir、curid、文件类型找寻符合条件选项 根据选项的id修改当前id 错误直接返回-1 char sql[1024]; - sprintf(sql, "select id from dirsys where preid = %d and tomb = 0 and user = '%s' and type = 'd' and name = '%s';", puser1->curid, puser1->username, dir); + sprintf(sql, "select id from vfsystem where preid = %d and tomb = 0 and user = '%s' and type = 'd' and name = '%s';", puser1->curid, puser1->username, dir); printf("%s\n", sql); int qret = mysql_query(mysql, sql); @@ -109,7 +109,7 @@ int changeusrPath(MYSQL* mysql, char* usrPath, userProcess_t* puser){ int lsCurrDir(int netfd, MYSQL* mysql, userProcess_t* puser){ char sql[1024]; - sprintf(sql, "select id, name, type, user from dirsys where preid = %d and tomb = 0 and user = '%s';", puser->curid, puser->username); + sprintf(sql, "select id, name, type, user from vfsystem where preid = %d and tomb = 0 and user = '%s';", puser->curid, puser->username); printf("%s\n", sql); int qret = mysql_query(mysql, sql); @@ -151,6 +151,11 @@ int lsCurrDir(int netfd, MYSQL* mysql, userProcess_t* puser){ send(netfd, &train2, sizeof(train2.length)+train2.length, MSG_NOSIGNAL);//发送数据给客户端send } + train_t train3; + bzero(&train3, sizeof(train3)); + train3.length = 0; + send(netfd, &train3, sizeof(train3.length), MSG_NOSIGNAL); //空车校验 + mysql_free_result(result); return 0; } @@ -166,30 +171,38 @@ int printfCurrPath(int netfd, MYSQL* mysql, userProcess_t* puser){ } while(puser1->curid != puser1->initid){ char sql[1024]; - sprintf(sql, "select preid, path from dirsys where id = %d and tomb = 0 and type = 'd' and user = '%s';", puser1->curid, puser1->username); + sprintf(sql, "select preid, path from vfsystem where id = %d and tomb = 0 and type = 'd' and user = '%s';", puser1->curid, puser1->username); printf("%s\n", sql); int qret = mysql_query(mysql, sql); if(qret != 0){ fprintf(stderr, "error:%s\n", mysql_error(mysql)); LOGRECORD(ERROR, "mysql_query"); + int status = -1; + send(netfd, &status, sizeof(int), MSG_NOSIGNAL); return -1; } MYSQL_RES* result = mysql_store_result(mysql); if(result == NULL){ LOGRECORD(ERROR, "mysql_store_result"); + int status = -1; + send(netfd, &status, sizeof(int), MSG_NOSIGNAL); return -1; } if(mysql_num_rows(result) == 0){ LOGRECORD(INFO, "mysql_num_rows"); + int status = -1; + send(netfd, &status, sizeof(int), MSG_NOSIGNAL); return -1; } MYSQL_ROW row; if((row = mysql_fetch_row(result)) == NULL){ LOGRECORD(ERROR, "mysql_fetch_row"); + int status = -1; + send(netfd, &status, sizeof(int), MSG_NOSIGNAL); return -1; } @@ -214,7 +227,7 @@ int printfCurrPath(int netfd, MYSQL* mysql, userProcess_t* puser){ int mkDir(char* dirname, MYSQL* mysql, userProcess_t* puser){ char sql[1024]; - sprintf(sql, "select id from dirsys where preid = %d and tomb = 0 and user = '%s' and type = 'd' and name = '%s';", puser->curid, puser->username, dirname); + sprintf(sql, "select id from vfsystem where preid = %d and tomb = 0 and user = '%s' and type = 'd' and name = '%s';", puser->curid, puser->username, dirname); printf("%s\n", sql); int qret = mysql_query(mysql, sql); @@ -236,7 +249,7 @@ int mkDir(char* dirname, MYSQL* mysql, userProcess_t* puser){ return -1; } - sprintf(sql, "insert into dirsys (name, type, preid, path, user, tomb) values ('%s', 'd', %d, '/%s', '%s', 0);", dirname, puser->curid, dirname, puser->username); + sprintf(sql, "insert into vfsystem (name, type, preid, path, user, tomb) values ('%s', 'd', %d, '/%s', '%s', 0);", dirname, puser->curid, dirname, puser->username); printf("%s\n", sql); qret = mysql_query(mysql, sql); @@ -252,7 +265,7 @@ int mkDir(char* dirname, MYSQL* mysql, userProcess_t* puser){ int rmDir(char* dirname, MYSQL* mysql, userProcess_t* puser){ //先查是否有该目录 char sql[1024]; - sprintf(sql, "select id from dirsys where preid = %d and tomb = 0 and user = '%s' and type = 'd' and name = '%s';", puser->curid, puser->username, dirname); + sprintf(sql, "select id from vfsystem where preid = %d and tomb = 0 and user = '%s' and type = 'd' and name = '%s';", puser->curid, puser->username, dirname); printf("%s\n", sql); int qret = mysql_query(mysql, sql); @@ -283,7 +296,7 @@ int rmDir(char* dirname, MYSQL* mysql, userProcess_t* puser){ int dirid = atoi(row[0]); mysql_free_result(result); //再查是否目录为空 - sprintf(sql, "select id from dirsys where preid = %d and tomb = 0 and user = '%s';", dirid, puser->username); + sprintf(sql, "select id from vfsystem where preid = %d and tomb = 0 and user = '%s';", dirid, puser->username); printf("%s\n", sql); qret = mysql_query(mysql, sql); @@ -304,9 +317,9 @@ int rmDir(char* dirname, MYSQL* mysql, userProcess_t* puser){ LOGRECORD(INFO, "mysql_num_rows"); return -1; } - + mysql_free_result(result); //目录为空进行删除 - sprintf(sql, "update dirsys set tomb = 1 where preid = %d and tomb = 0 and user = '%s' and type = 'd' and name = '%s';", puser->curid, puser->username, dirname); + sprintf(sql, "update vfsystem set tomb = 1 where preid = %d and tomb = 0 and user = '%s' and type = 'd' and name = '%s';", puser->curid, puser->username, dirname); printf("%s\n", sql); qret = mysql_query(mysql, sql); @@ -323,7 +336,7 @@ int rmDir(char* dirname, MYSQL* mysql, userProcess_t* puser){ int deleteServerFile(char* filename, MYSQL* mysql, userProcess_t* puser){ //先查是否有该文件 char sql[1024]; - sprintf(sql, "select id from dirsys where preid = %d and tomb = 0 and user = '%s' and type = 'f' and name = '%s';", puser->curid, puser->username, filename); + sprintf(sql, "select id from vfsystem where preid = %d and tomb = 0 and user = '%s' and type = 'f' and name = '%s';", puser->curid, puser->username, filename); printf("%s\n", sql); int qret = mysql_query(mysql, sql); @@ -348,7 +361,7 @@ int deleteServerFile(char* filename, MYSQL* mysql, userProcess_t* puser){ mysql_free_result(result); //删除文件 - sprintf(sql, "update dirsys set tomb = 1 where preid = %d and tomb = 0 and user = '%s' and type = 'f' and name = '%s';", puser->curid, puser->username, filename); + sprintf(sql, "update vfsystem set tomb = 1 where preid = %d and tomb = 0 and user = '%s' and type = 'f' and name = '%s';", puser->curid, puser->username, filename); printf("%s\n", sql); qret = mysql_query(mysql, sql);