aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlonkaars <loek@pipeframe.xyz>2021-06-04 09:42:01 +0200
committerlonkaars <loek@pipeframe.xyz>2021-06-04 09:42:01 +0200
commit9dcdd85527bb2d981548af4d621f9c4731b5c0a2 (patch)
treefce5a9c96be17709079c233a0953c0311543e2b5
parentcb0c971da01dbea560d09ce0eddac4093a899f46 (diff)
ignore existing files with filesize/lazy/none methods
-rw-r--r--musicopy.c26
-rw-r--r--rc.ini7
-rw-r--r--readme.md22
3 files changed, 43 insertions, 12 deletions
diff --git a/musicopy.c b/musicopy.c
index 1a44351..67ef96a 100644
--- a/musicopy.c
+++ b/musicopy.c
@@ -7,6 +7,7 @@
#include <ftw.h>
#include <fnmatch.h>
#include <wordexp.h>
+#include <sys/stat.h>
char* music_dir;
char* playlist_dir;
@@ -127,6 +128,22 @@ void fix_include_exclude(char*** listv, int listc) {
}
}
+bool duplicate(char* source, char* dest) {
+ if (strcmp(existing, "none") == 0) return true;
+ else if (strcmp(existing, "lazy") == 0) return false;
+ else if (strcmp(existing, "size") == 0) {
+ struct stat src_st, dst_st;
+ stat(source, &src_st);
+ stat(dest, &dst_st);
+ return src_st.st_size != dst_st.st_size;
+ }
+ else if (strcmp(existing, "hash") == 0) {
+ printf("compare hash\n");
+ }
+
+ return false;
+}
+
void copy(const char* fullpath) {
int baselen = strlen(music_dir);
char* basepath = substr(fullpath, baselen);
@@ -139,7 +156,14 @@ void copy(const char* fullpath) {
mkpath(destfolder, 0775);
char* sourcepath = strdup(fullpath);
- cp(sourcepath, destpath);
+
+ bool copy = true;
+ if(access(destpath, F_OK) == 0) copy = duplicate(sourcepath, destpath);
+ if(copy) {
+ cp(sourcepath, destpath);
+ printf("%s -> %s\n", sourcepath, destpath);
+ }
+
free(sourcepath);
}
diff --git a/rc.ini b/rc.ini
index 0be989a..cc7fcc0 100644
--- a/rc.ini
+++ b/rc.ini
@@ -11,8 +11,9 @@ target_playlist_dir = /mnt/player/Playlists
# include = folders to include/**
# don't copy existing files
-# lazy = only check file size
-# full = compare sha1 hash
# none = blindly overwrite files
-# existing = lazy
+# lazy = only overwrite if a file doesn't exists
+# size = only overwrite if file size doesn't match
+# hash = only overwrite if sha1 hash doesn't match
+existing = lazy
diff --git a/readme.md b/readme.md
index dc019d0..4bd948e 100644
--- a/readme.md
+++ b/readme.md
@@ -4,10 +4,10 @@ a simple utility that copies music and playlists from a folder to another folder
## 'amazing' features:
-- glob include/exclude patterns
-- doesn't copy existing files
-- multiple different configuration sections for different media players or libraries
-- stores a copy of your playlist to merge differences created on another media player
+- [x] glob include/exclude patterns
+- [x] doesn't copy existing files
+- [x] multiple different configuration sections for different media players or libraries
+- [ ] stores a copy of your playlist to merge differences created on another media player
## dependencies
@@ -23,15 +23,21 @@ the config file is in ini format. here's the options:
music_dir = ~/music
playlist_dir = ~/playlists
-exclude = junk/**
- i don't like this music/**
+target_music_dir = /mnt/player/Music
+target_playlist_dir = /mnt/player/Playlists
+
+# multi-line ini works too (multiple definitions
+# of the same key also works)
+# exclude = junk/**
+# i don't like this music/**
# include = folders to include/**
# don't copy existing files
-# lazy = only check file size
-# full = compare sha1 hash
# none = blindly overwrite files
+# lazy = only overwrite if a file doesn't exists
+# size = only overwrite if file size doesn't match
+# hash = only overwrite if sha1 hash doesn't match
existing = lazy
```