diff --git a/vfs/ChangeLog b/vfs/ChangeLog index 4f91b2c7a..398f679e3 100644 --- a/vfs/ChangeLog +++ b/vfs/ChangeLog @@ -1,3 +1,10 @@ +2003-10-27 Pavel Roskin + + * 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 * direntry.c (vfs_s_find_inode): Only allow search from root. diff --git a/vfs/cpio.c b/vfs/cpio.c index 7a294c147..a31413ac8 100644 --- a/vfs/cpio.c +++ b/vfs/cpio.c @@ -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); } diff --git a/vfs/tar.c b/vfs/tar.c index f62cafef1..2ad361297 100644 --- a/vfs/tar.c +++ b/vfs/tar.c @@ -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); } diff --git a/vfs/vfs.c b/vfs/vfs.c index f55ea3afb..5719c1b27 100644 --- a/vfs/vfs.c +++ b/vfs/vfs.c @@ -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;