X-Git-Url: https://git.distorted.org.uk/~mdw/disorder/blobdiff_plain/460b9539a7c15580e41a71bbc0f47ae776238915..d76bbdea349bf3856172ce9599e657d566e91162:/clients/disorderfm.c?ds=inline
diff --git a/clients/disorderfm.c b/clients/disorderfm.c
index 0fd4fa0..241b701 100644
--- a/clients/disorderfm.c
+++ b/clients/disorderfm.c
@@ -1,25 +1,27 @@
/*
* This file is part of DisOrder.
- * Copyright (C) 2006 Richard Kettlewell
+ * Copyright (C) 2006, 2007, 2008 Richard Kettlewell
*
- * This program is free software; you can redistribute it and/or modify
+ * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
+ * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
* You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
- * USA
+ * along with this program. If not, see .
*/
-
-#include
-#include "types.h"
+/** @file clients/disorderfm.c
+ * @brief DisOrder file manager
+ *
+ * Intended to support encoding conversion, tag extraction, etc. Not yet
+ * complete (and hasn't been worked on for ages).
+ */
+#include "common.h"
#include
#include
@@ -29,7 +31,6 @@
#include
#include
#include
-#include
#include
#include "syscalls.h"
@@ -38,6 +39,7 @@
#include "charset.h"
#include "defs.h"
#include "mem.h"
+#include "version.h"
/* Arguments etc ----------------------------------------------------------- */
@@ -127,13 +129,6 @@ static void help(void) {
exit(0);
}
-/* display version number and terminate */
-static void version(void) {
- xprintf("disorderfm version %s\n", disorder_version_string);
- xfclose(stdout);
- exit(0);
-}
-
/* Utilities --------------------------------------------------------------- */
/* Copy FROM to TO. Has the same signature as link/symlink. */
@@ -141,6 +136,7 @@ static int copy(const char *from, const char *to) {
int fdin, fdout;
char buffer[4096];
int n;
+ struct stat sb;
if((fdin = open(from, O_RDONLY)) < 0)
fatal(errno, "error opening %s", from);
@@ -151,6 +147,12 @@ static int copy(const char *from, const char *to) {
fatal(errno, "error writing to %s", to);
}
if(n < 0) fatal(errno, "error reading %s", from);
+ if(fstat(fdin, &sb) < 0)
+ fatal(errno, "error stating %s", from);
+ if(fchown(fdout, sb.st_uid, sb.st_gid) < 0)
+ fatal(errno, "error chowning %s", from);
+ if(fchmod(fdout, sb.st_mode & 07777) < 0)
+ fatal(errno, "error chmoding %s", from);
if(close(fdout) < 0) fatal(errno, "error closing %s", to);
xclose(fdin);
return 0;
@@ -315,7 +317,20 @@ static void visit(const char *path, const char *destpath) {
/* We create the directory on the destination side. If it already exists,
* that's fine. */
- if(dirmaker(fulldestpath, 0777) < 0 && errno != EEXIST) {
+ if(dirmaker(fulldestpath, 0700) == 0) {
+ if(dirmaker != nomkdir) {
+ /* Created new directory. Adjust permissions and ownership to match the
+ * old one. */
+ if(chown(fulldestpath, sb.st_uid, sb.st_gid) < 0) {
+ error(errno, "cannot chown %s", errdestpath);
+ ++errors;
+ }
+ if(chmod(fulldestpath, sb.st_mode & 07777) < 0) {
+ error(errno, "cannot chmod %s", errdestpath);
+ ++errors;
+ }
+ }
+ } else if(errno != EEXIST) {
error(errno, "cannot mkdir %s", errdestpath);
++errors;
return;
@@ -351,12 +366,12 @@ int main(int argc, char **argv) {
int n;
struct pattern *p;
- mem_init(1);
+ mem_init();
if(!setlocale(LC_CTYPE, "")) fatal(errno, "error calling setlocale");
while((n = getopt_long(argc, argv, "hVdf:t:i:e:ET:u:wlscn", options, 0)) >= 0) {
switch(n) {
case 'h': help();
- case 'V': version();
+ case 'V': version("disorderfm");
case 'd': debugging = 1; break;
case 'f': fromencoding = optarg; break;
case 't': toencoding = optarg; break;
@@ -411,4 +426,3 @@ fill-column:79
indent-tabs-mode:nil
End:
*/
-/* arch-tag:YWy+lwnCOS0d8Q5hjJ5gyQ */