* cpio.c (cpio_ungetlocalcopy): Remove.

* tar.c (tar_ungetlocalcopy): Likewise.
* vfs.c (mc_def_ungetlocalcopy): Add support for read-only
filesystems.
This commit is contained in:
Pavel Roskin 2003-10-27 21:01:00 +00:00
parent 0e71b37f2a
commit 4ee3f26133
4 changed files with 28 additions and 32 deletions

View File

@ -1,3 +1,10 @@
2003-10-27 Pavel Roskin <proski@gnu.org>
* cpio.c (cpio_ungetlocalcopy): Remove.
* tar.c (tar_ungetlocalcopy): Likewise.
* vfs.c (mc_def_ungetlocalcopy): Add support for read-only
filesystems.
2003-10-26 Pavel Roskin <proski@gnu.org>
* direntry.c (vfs_s_find_inode): Only allow search from root.

View File

@ -571,13 +571,6 @@ static int cpio_read(void *fh, char *buffer, int count)
return count;
}
static int cpio_ungetlocalcopy(struct vfs_class *me, char *path, char *local, int has_changed)
{
/* We do just nothing. (We are read only and do not need to free local,
since it will be freed when tar archive will be freed */
return 0;
}
static int cpio_fh_open(struct vfs_class *me, struct vfs_s_fh *fh, int flags, int mode)
{
if ((flags & O_ACCMODE) != O_RDONLY) ERRNOR (EROFS, -1);
@ -603,6 +596,5 @@ init_cpiofs (void)
vfs_cpiofs_ops.read = cpio_read;
vfs_cpiofs_ops.write = NULL;
vfs_cpiofs_ops.setctl = NULL;
vfs_cpiofs_ops.ungetlocalcopy = cpio_ungetlocalcopy;
vfs_register_class (&vfs_cpiofs_ops);
}

View File

@ -607,14 +607,6 @@ static int tar_read (void *fh, char *buffer, int count)
return count;
}
static int tar_ungetlocalcopy (struct vfs_class *me, char *path, char *local, int has_changed)
{
/* We do just nothing. (We are read only and do not need to free local,
since it will be freed when tar archive will be freed */
/* We have to report error if file has changed */
ERRNOR (EROFS, -has_changed);
}
static int tar_fh_open (struct vfs_class *me, struct vfs_s_fh *fh, int flags, int mode)
{
if ((flags & O_ACCMODE) != O_RDONLY) ERRNOR (EROFS, -1);
@ -639,7 +631,6 @@ init_tarfs (void)
vfs_tarfs_ops.data = &tarfs_subclass;
vfs_tarfs_ops.read = tar_read;
vfs_tarfs_ops.write = NULL;
vfs_tarfs_ops.ungetlocalcopy = tar_ungetlocalcopy;
vfs_tarfs_ops.setctl = NULL;
vfs_register_class (&vfs_tarfs_ops);
}

View File

@ -1079,31 +1079,35 @@ mc_getlocalcopy (const char *pathname)
}
int
mc_def_ungetlocalcopy (struct vfs_class *vfs, char *filename, char *local, int has_changed)
{ /* Dijkstra probably hates me... But he should teach me how to do this nicely. */
mc_def_ungetlocalcopy (struct vfs_class *vfs, char *filename, char *local,
int has_changed)
{
int fdin = -1, fdout = -1, i;
if (has_changed){
char buffer [8192];
fdin = open (local, O_RDONLY);
if (fdin == -1)
if (has_changed) {
char buffer[8192];
if (!vfs->write)
goto failed;
fdout = mc_open (filename, O_WRONLY | O_TRUNC);
if (fdout == -1)
fdin = open (local, O_RDONLY);
if (fdin == -1)
goto failed;
while ((i = read (fdin, buffer, sizeof (buffer))) > 0){
fdout = mc_open (filename, O_WRONLY | O_TRUNC);
if (fdout == -1)
goto failed;
while ((i = read (fdin, buffer, sizeof (buffer))) > 0) {
if (mc_write (fdout, buffer, i) != i)
goto failed;
}
if (i == -1)
goto failed;
if (close (fdin)==-1) {
if (close (fdin) == -1) {
fdin = -1;
goto failed;
}
fdin = -1;
if (mc_close (fdout)==-1) {
if (mc_close (fdout) == -1) {
fdout = -1;
goto failed;
}
@ -1112,10 +1116,12 @@ mc_def_ungetlocalcopy (struct vfs_class *vfs, char *filename, char *local, int h
g_free (local);
return 0;
failed:
failed:
message (1, _("Changes to file lost"), filename);
if (fdout!=-1) mc_close(fdout);
if (fdin!=-1) close(fdin);
if (fdout != -1)
mc_close (fdout);
if (fdin != -1)
close (fdin);
unlink (local);
g_free (local);
return -1;