Skip to content

Commit 6bd1b81

Browse files
committed
Bug fixes in Core and Installers.
1 parent 18541b0 commit 6bd1b81

File tree

25 files changed

+328
-406
lines changed

25 files changed

+328
-406
lines changed

core/network/locfile.c

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,8 @@ inline int LocFileRead( LocFile* file, long long offset, long long size )
8787
}
8888

8989
file->lf_FileSize = size;
90-
FILE* fp = file->fp;
91-
fseek( fp, offset, SEEK_SET );
92-
int result = fread( file->lf_Buffer, 1, size, fp );
90+
fseek( file->lf_Fp, offset, SEEK_SET );
91+
int result = fread( file->lf_Buffer, 1, size, file->lf_Fp );
9392
if( result < size )
9493
{
9594
return result;
@@ -121,14 +120,14 @@ LocFile* LocFileNew( char* path, unsigned int flags )
121120
struct stat st;
122121
if( stat( path, &st ) < 0 )
123122
{
124-
FERROR( "Cannot stat file.\n" );
123+
FERROR( "Cannot stat file: '%s'.\n", path );
125124
fclose( fp );
126125
return NULL;
127126
}
128127

129128
if( S_ISDIR( st.st_mode ) )
130129
{
131-
FERROR( "Is a directory. Can not open.\n" );
130+
FERROR( "'%s' is a directory. Can not open.\n", path );
132131
fclose( fp );
133132
return NULL;
134133
}
@@ -145,10 +144,10 @@ LocFile* LocFileNew( char* path, unsigned int flags )
145144

146145
DEBUG("PATH: %s\n", fo->lf_Path );
147146

148-
memcpy( &(fo->info), &st, sizeof( struct stat) );
147+
memcpy( &(fo->lf_Info), &st, sizeof( struct stat) );
149148
//fstat( fp, &(fo->info));
150149

151-
fo->fp = fp;
150+
fo->lf_Fp = fp;
152151
//fseek( fp, 0L, SEEK_END );
153152

154153
fseek( fp, 0, SEEK_END );
@@ -228,10 +227,10 @@ int LocFileReload( LocFile *file, char *path )
228227
DEBUG("File %s will be reloaded\n", path );
229228
//char *tmpPath = NULL;
230229

231-
if( file->fp )
230+
if( file->lf_Fp )
232231
{
233-
fclose( file->fp );
234-
file->fp = NULL;
232+
fclose( file->lf_Fp );
233+
file->lf_Fp = NULL;
235234
}
236235

237236
//if( file->lf_Path )
@@ -258,9 +257,9 @@ int LocFileReload( LocFile *file, char *path )
258257
FERROR("Cannot run stat on file: %s!\n", path);
259258
return -2;
260259
}
261-
memcpy( &(file->info), &st, sizeof(stat) );
260+
memcpy( &(file->lf_Info), &st, sizeof(stat) );
262261

263-
file->fp = fp;
262+
file->lf_Fp = fp;
264263
fseek( fp, 0, SEEK_END );
265264
long fsize = ftell( fp );
266265
fseek( fp, 0, SEEK_SET ); //same as rewind(f);
@@ -287,10 +286,10 @@ void LocFileDelete( LocFile* file )
287286
{
288287
FFree( file->lf_Filename );
289288
}
290-
if( file->fp )
289+
if( file->lf_Fp )
291290
{
292-
fclose( file->fp );
293-
file->fp = NULL;
291+
fclose( file->lf_Fp );
292+
file->lf_Fp = NULL;
294293
}
295294
if( file->lf_Path )
296295
{

core/network/locfile.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,10 @@ typedef struct LocFile
5454
char *lf_Buffer;
5555
unsigned long lf_FileSize;
5656

57-
FILE* fp; // File pointer
58-
int fd; // File descriptor
59-
struct stat info;
57+
FILE* lf_Fp; // File pointer
58+
int lf_Fd; // File descriptor
59+
struct stat lf_Info;
60+
time_t lf_ModificationTimestamp;
6061

6162
FUQUAD lf_FileUsed;
6263
struct MinNode node;

core/network/protocol_http.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ inline int ReadServerFile( Uri *uri, char *locpath, BufString *dstbs, int *resul
187187

188188

189189
//DEBUG1("\n\n\n\n\n SIZE %lld stat %lld\n\n\n\n",attr.st_mtime ,file->info.st_mtime );
190-
if( attr.st_mtime != file->info.st_mtime )
190+
if( attr.st_mtime != file->lf_Info.st_mtime )
191191
{
192192
LocFileReload( file, completePath->raw);
193193
}
@@ -1129,7 +1129,7 @@ extern inline Http *ProtocolHttp( Socket* sock, char* data, unsigned int length
11291129

11301130
//DEBUG1("\n\n\n\n\n SIZE %lld stat %lld NAME %s\n\n\n\n",attr.st_mtime ,file->info.st_mtime,completePath->raw );
11311131
Log( FLOG_DEBUG, "[ProtocolHttp] File will be reloaded\n");
1132-
if( attr.st_mtime != file->info.st_mtime )
1132+
if( attr.st_mtime != file->lf_Info.st_mtime )
11331133
{
11341134
LocFileReload( file, decoded );
11351135
}

core/system/cache/cache_manager.c

Lines changed: 18 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,6 @@ void CacheManagerDelete( CacheManager *cm )
9090
FFree( cm->cm_CacheFileGroup );
9191
}
9292

93-
CacheUserFilesDeleteAll( cm->cm_CacheUserFiles );
9493
/*
9594
LocFile *lf = cm->cm_LocFileCache;
9695
while( lf != NULL )
@@ -208,42 +207,19 @@ int CacheManagerFilePut( CacheManager *cm, LocFile *lf )
208207
/**
209208
* function store LocFile inside cache (User cache)
210209
*
211-
* @param cm pointer to CacheManager which will store file
212-
* @param usr pointer to User structure
210+
* @param locusr pointer to User structure
213211
* @param lf pointer to LocFile structure which will be stored in cache
214212
* @return 0 when success, otherwise error number
215213
*/
216-
int CacheManagerUserFilePut( CacheManager *cm, void *usr, LocFile *lf )
214+
int CacheManagerUserFilePut( void *locusr, LocFile *lf )
217215
{
218-
if( cm != NULL )
216+
if( locusr != NULL )
219217
{
220218
// trying to find user assigned to CacheUserFiles, on the end we should assign cache to user
221-
CacheUserFiles *cusf = cm->cm_CacheUserFiles;
222-
while( cusf != NULL )
223-
{
224-
if( cusf->cuf_Usr == usr )
225-
{
226-
break;
227-
}
228-
cusf = (CacheUserFiles *)cusf->node.mln_Succ;
229-
}
230-
231-
// if CacheUserFiles exist, we are adding file to list
232-
if( cusf != NULL )
233-
{
234-
CacheUserFilesAddFile( cusf, lf );
235-
}
236-
else
237-
{
238-
CacheUserFiles *newcuf = CacheUserFilesNew( usr );
239-
if( newcuf != NULL )
240-
{
241-
newcuf->node.mln_Succ = (MinNode *)cm->cm_CacheUserFiles;
242-
cm->cm_CacheUserFiles = newcuf;
243-
244-
CacheUserFilesAddFile( newcuf, lf );
245-
}
246-
}
219+
User *usr = (User *)locusr;
220+
221+
CacheUserFilesAddFile( &(usr->u_FileCache), lf );
222+
247223
}
248224
return 0;
249225
}
@@ -252,25 +228,16 @@ int CacheManagerUserFilePut( CacheManager *cm, void *usr, LocFile *lf )
252228
/**
253229
* function get LocFile from cache (User cache)
254230
*
255-
* @param cm pointer to CacheManager where LocFile will be searched
256-
* @param usr pointer to User structure
231+
* @param locusr pointer to User structure
257232
* @param path full path to file (include device name)
258233
* @return LocFile structure when success, otherwise NULL
259234
*/
260-
LocFile *CacheManagerUserFileGet( CacheManager *cm, void *usr, char *path )
235+
LocFile *CacheManagerUserFileGet( void *locusr, char *path )
261236
{
262-
if( cm != NULL )
237+
if( locusr != NULL )
263238
{
264239
// trying to find user assigned to CacheUserFiles, on the end we should assign cache to user
265-
CacheUserFiles *cusf = cm->cm_CacheUserFiles;
266-
while( cusf != NULL )
267-
{
268-
if( cusf->cuf_Usr == usr )
269-
{
270-
break;
271-
}
272-
cusf = (CacheUserFiles *)cusf->node.mln_Succ;
273-
}
240+
User *usr = (User *)locusr;
274241

275242
uint64_t hash[ 2 ];
276243
MURMURHASH3( path, strlen(path), hash );
@@ -279,18 +246,16 @@ LocFile *CacheManagerUserFileGet( CacheManager *cm, void *usr, char *path )
279246
unsigned char id = (unsigned char)hfirstChar[0];
280247

281248
// if CacheUserFiles exist, we are trying to find file
282-
if( cusf != NULL )
249+
250+
LocFile *lf = usr->u_FileCache->cuf_File;
251+
while( lf != NULL )
283252
{
284-
LocFile *lf = cusf->cuf_File;
285-
while( lf != NULL )
253+
if( memcmp( hash, lf->hash, sizeof(hash) ) == 0 )
286254
{
287-
if( memcmp( hash, lf->hash, sizeof(hash) ) == 0 )
288-
{
289-
lf->lf_FileUsed++;
290-
return lf;
291-
}
292-
lf = (LocFile *)lf->node.mln_Succ;
255+
lf->lf_FileUsed++;
256+
return lf;
293257
}
258+
lf = (LocFile *)lf->node.mln_Succ;
294259
}
295260
}
296261
return 0;

core/system/cache/cache_manager.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ typedef struct CacheManager
5757
{
5858
CacheFileGroup *cm_CacheFileGroup;
5959
LocFile *cm_LocFileCache;
60-
CacheUserFiles *cm_CacheUserFiles;
6160
FUQUAD cm_CacheSize;
6261
FUQUAD cm_CacheMax;
6362
}CacheManager;

core/system/fsys/fs_manager_web.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333
#include <util/md5.h>
3434
#include <system/fsys/door_notification.h>
3535
#include <stdlib.h>
36+
#include <system/cache/cache_user_files.h>
37+
#include <system/cache/cache_manager.h>
3638

3739
/**
3840
* Filesystem web calls handler
@@ -697,6 +699,8 @@ Http *FSMWebRequest( void *m, char **urlpath, Http *request, UserSession *logged
697699
FBOOL have = FSManagerCheckAccess( l->sl_FSM, path, actDev->f_ID, loggedSession->us_User, "-R----" );
698700
if( have == TRUE )
699701
{
702+
LocFile *lf = CacheManagerUserFileGet( loggedSession->us_User, origDecodedPath );
703+
700704
if( mode != NULL && strcmp( mode, "rs" ) == 0 ) // read stream
701705
{
702706
File *fp = (File *)actFS->FileOpen( actDev, path, mode );

core/system/fsys/fsys.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ FHandler *FHandlerCreate( const char *path, const char *name )
9191
memcpy( fsys->Path, path, len );
9292
}
9393

94-
if( ( fsys->handle = dlopen ( path, RTLD_LAZY ) ) != NULL )
94+
if( ( fsys->handle = dlopen( path, RTLD_NOW|RTLD_GLOBAL ) ) != NULL )
9595
{
9696
DEBUG("SYSTEMLIB FSYSCREATE, getting pointer to libs\n");
9797

@@ -125,6 +125,7 @@ FHandler *FHandlerCreate( const char *path, const char *name )
125125
fsys->InfoSet = dlsym( fsys->handle, "InfoSet" );
126126

127127
fsys->Dir = dlsym( fsys->handle, "Dir");
128+
fsys->GetChangeTimestamp = dlsym( fsys->handle, "GetChangeTimestamp" );
128129

129130
fsys->init( fsys );
130131
}
@@ -151,7 +152,6 @@ void FHandlerDelete( FHandler *fsys )
151152
{
152153
if( fsys != NULL )
153154
{
154-
DEBUG( "\t\t\t\tFSYS deinit %p", fsys->deinit );
155155
fsys->deinit( fsys );
156156

157157
if( fsys->Name )
@@ -166,7 +166,7 @@ void FHandlerDelete( FHandler *fsys )
166166

167167
if( fsys->handle )
168168
{
169-
dlclose ( fsys->handle );
169+
dlclose( fsys->handle );
170170
}
171171

172172
FFree( fsys );

core/system/fsys/fsys.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
#include <util/hooks.h>
3636
#include <util/hashmap.h>
3737
#include <util/tagitem.h>
38-
//#include <user/userlibrary.h>
3938
#include <util/base64.h>
4039
#include <util/buffered_string.h>
4140
#include <system/fsys/file.h>
@@ -88,19 +87,16 @@ typedef struct FHandler
8887
char *(*GetSuffix)();
8988
char *(*GetPrefix)();
9089

91-
// ONLY USED BY system.library
9290
void *(*Mount)( struct FHandler *s, struct TagItem *ti, User *us );
9391
int (*UnMount)( struct FHandler *s, void *f, User *usr );
9492
int (*Release)( struct FHandler *s, void *f );
95-
96-
//
93+
9794
void *(*FileOpen)( struct File *s, const char *path, char *mode );
9895
int (*FileClose)( struct File *s, void *fp );
9996
int (*FileRead)( struct File *s, char *buf, int size );
10097
int (*FileWrite)( struct File *s, char *buf, int size );
10198
int (*FileSeek)( struct File *s, int pos );
10299

103-
// mount / unmount will be system.library function, will return pointer to root file
104100
int (*MakeDir)( struct File *s, const char *path );
105101
int (*Delete)( struct File *s, const char *path );
106102
int (*Rename)( struct File *s, const char *path, const char *nname );
@@ -113,6 +109,7 @@ typedef struct FHandler
113109
BufString *(*Info)( struct File *s, const char *path );
114110
BufString *(*Call)( struct File *s, const char *path, char *args );
115111
BufString *(*Dir)( struct File *s, const char *path );
112+
FQUAD (*GetChangeTimestamp)( struct File *s, const char *path );
116113

117114
void *fh_SpecialData;
118115
}FHandler;

core/system/fsysdyn/fsysinram.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ char *GetFileName( const char *path )
110110

111111
void init( struct FHandler *s )
112112
{
113-
//s->Info = dlsym( s->handle, "Info" );
113+
DEBUG("[RAMFS] init\n");
114114
}
115115

116116
//
@@ -119,7 +119,7 @@ void init( struct FHandler *s )
119119

120120
void deinit( struct FHandler *s )
121121
{
122-
122+
DEBUG("[RAMFS] deinit\n");
123123
}
124124

125125
//
@@ -164,8 +164,6 @@ void *Mount( struct FHandler *s, struct TagItem *ti, User *usr )
164164
lptr++;
165165
}
166166

167-
init( s );
168-
169167
SpecialData *srd = calloc( 1, sizeof( SpecialData ) );
170168
srd->root = INRAMFileNew( INRAM_ROOT, name, name );
171169
dev->f_SpecialData = srd;
@@ -648,6 +646,15 @@ void FillStat( BufString *bs, INRAMFile *nf, File *d, const char *path )
648646
//DEBUG( "FILLSTAT END\n");
649647
}
650648

649+
//
650+
// Get information about last file changes (seconds from 1970)
651+
//
652+
653+
FQUAD GetChangeTimestamp( struct File *s, const char *path )
654+
{
655+
return (FQUAD)0;
656+
}
657+
651658
//
652659
// Get info about file/folder and return as "string"
653660
//

0 commit comments

Comments
 (0)