Skip to content

Commit

Permalink
Initial file permission work.
Browse files Browse the repository at this point in the history
  • Loading branch information
icculus committed May 3, 2007
1 parent e23225e commit fba19dd
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 6 deletions.
5 changes: 5 additions & 0 deletions archive_zip.c
Expand Up @@ -219,6 +219,7 @@ typedef struct _ZIPentry
char *name; /* Name of file in archive */
struct _ZIPentry *symlink; /* NULL or file we symlink to */
#if __MOJOSETUP__
PHYSFS_uint16 perms;
char *linkdest;
#endif
ZipResolveType resolved; /* Have we resolved file/symlink? */
Expand Down Expand Up @@ -1095,6 +1096,7 @@ static int zip_load_entry(void *in, ZIPentry *entry, PHYSFS_uint32 ofs_fixup)
entry->offset += ofs_fixup;

#if __MOJOSETUP__
entry->perms = (external_attr >> 16) & 0xFFFF;
entry->linkdest = NULL;
#endif

Expand Down Expand Up @@ -1747,6 +1749,8 @@ static const MojoArchiveEntry *MojoArchive_zip_enumNext(MojoArchive *ar)
ar->prevEnum.filename = xstrdup(entry->name);
ar->prevEnum.filesize = entry->uncompressed_size;
ar->prevEnum.type = MOJOARCHIVE_ENTRY_FILE;
ar->prevEnum.perms = entry->perms;

if (entry->name[strlen(entry->name) - 1] == '/')
ar->prevEnum.type = MOJOARCHIVE_ENTRY_DIR;
else if (MojoArchive_zip_entry_is_symlink(info, entry))
Expand Down Expand Up @@ -1779,6 +1783,7 @@ static const MojoArchiveEntry *MojoArchive_zip_enumNext(MojoArchive *ar)

ar->prevEnum.filesize = entry->uncompressed_size;
ar->prevEnum.type = MOJOARCHIVE_ENTRY_FILE;
ar->prevEnum.perms = entry->perms;
if (ptr != NULL)
ar->prevEnum.type = MOJOARCHIVE_ENTRY_DIR;
else if (MojoArchive_zip_entry_is_symlink(info, entry))
Expand Down
6 changes: 3 additions & 3 deletions fileio.c
Expand Up @@ -62,7 +62,7 @@ void MojoArchive_resetEntry(MojoArchiveEntry *info, int basetoo)

// !!! FIXME: I'd rather not use a callback here, but I can't see a cleaner
// !!! FIXME: way right now...
boolean MojoInput_toPhysicalFile(MojoInput *in, const char *fname,
boolean MojoInput_toPhysicalFile(MojoInput *in, const char *fname, uint16 perms,
MojoInput_FileCopyCallback cb, void *data)
{
FILE *out = NULL;
Expand All @@ -71,8 +71,6 @@ boolean MojoInput_toPhysicalFile(MojoInput *in, const char *fname,
int64 flen = 0;
int64 bw = 0;

STUBBED("file permissions?");

if (in == NULL)
return false;

Expand Down Expand Up @@ -119,6 +117,7 @@ boolean MojoInput_toPhysicalFile(MojoInput *in, const char *fname,
return false;
} // if

MojoPlatform_chmod(fname, perms);
return true;
} // MojoInput_toPhysicalFile

Expand Down Expand Up @@ -463,6 +462,7 @@ static const MojoArchiveEntry *MojoArchive_dir_enumNext(MojoArchive *ar)
ar->prevEnum.type = MOJOARCHIVE_ENTRY_UNKNOWN;
else
{
ar->prevEnum.perms = statbuf.st_mode;
ar->prevEnum.filesize = statbuf.st_size;
if (S_ISREG(statbuf.st_mode))
ar->prevEnum.type = MOJOARCHIVE_ENTRY_FILE;
Expand Down
3 changes: 2 additions & 1 deletion fileio.h
Expand Up @@ -54,6 +54,7 @@ typedef struct MojoArchiveEntry
char *linkdest;
MojoArchiveEntryType type;
int64 filesize;
uint16 perms;
} MojoArchiveEntry;

void MojoArchive_resetEntry(MojoArchiveEntry *info, int basetoo);
Expand Down Expand Up @@ -89,7 +90,7 @@ MojoArchive *MojoArchive_initBaseArchive(void);
void MojoArchive_deinitBaseArchive(void);

typedef boolean (*MojoInput_FileCopyCallback)(int percent, void *data);
boolean MojoInput_toPhysicalFile(MojoInput *in, const char *fname,
boolean MojoInput_toPhysicalFile(MojoInput *in, const char *fname, uint16 perms,
MojoInput_FileCopyCallback cb, void *data);

#ifdef __cplusplus
Expand Down
7 changes: 5 additions & 2 deletions lua_glue.c
Expand Up @@ -591,7 +591,8 @@ static int luahook_writefile(lua_State *L)
MojoInput *in = archive->openCurrentEntry(archive);
if (in != NULL)
{
retval = MojoInput_toPhysicalFile(in, path, writefile_callback, NULL);
retval = MojoInput_toPhysicalFile(in, path, archive->prevEnum.perms,
writefile_callback, NULL);
in->close(in);
} // if
} // if
Expand Down Expand Up @@ -727,7 +728,9 @@ static int luahook_movefile(lua_State *L)
MojoInput *in = MojoInput_newFromFile(src);
if (in != NULL)
{
retval = MojoInput_toPhysicalFile(in, dst, NULL, NULL);
uint16 perms = 0;
MojoPlatform_perms(src, &perms);
retval = MojoInput_toPhysicalFile(in, dst, perms, NULL, NULL);
in->close(in);
if (retval)
{
Expand Down
6 changes: 6 additions & 0 deletions platform.h
Expand Up @@ -47,6 +47,12 @@ boolean MojoPlatform_rename(const char *src, const char *dst);
// !!! FIXME: comment me.
boolean MojoPlatform_exists(const char *dir, const char *fname);

// !!! FIXME: comment me.
boolean MojoPlatform_perms(const char *fname, uint16 *p);

// !!! FIXME: comment me.
boolean MojoPlatform_chmod(const char *fname, uint16 p);

// !!! FIXME: comment me.
char *MojoPlatform_findMedia(const char *uniquefile);

Expand Down
19 changes: 19 additions & 0 deletions platform/unix.c
Expand Up @@ -486,6 +486,25 @@ boolean MojoPlatform_exists(const char *dir, const char *fname)
} // MojoPlatform_exists


boolean MojoPlatform_perms(const char *fname, uint16 *p)
{
boolean retval = false;
struct stat statbuf;
if (stat(fname, &statbuf) != -1)
{
*p = statbuf.st_mode;
retval = true;
} // if
return retval;
} // MojoPlatform_perms


boolean MojoPlatform_chmod(const char *fname, uint16 p)
{
return (chmod(fname, p) != -1);
} // MojoPlatform_chmod


char *MojoPlatform_findMedia(const char *uniquefile)
{
#if MOJOSETUP_HAVE_SYS_UCRED_H
Expand Down

0 comments on commit fba19dd

Please sign in to comment.