-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconflictor
More file actions
57 lines (53 loc) · 2.75 KB
/
conflictor
File metadata and controls
57 lines (53 loc) · 2.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/bin/bash
#Search for the name of the file in both A and B : Argument given
#Look up the line for both A and B
#Look up the mod date
#Compare the dates and choose the latest
conflict #name, nameline, line, databaseA, databaseS, databaseB, pathToA, pathToB
{
echo "Conflict"
#name, nameline, line, databaseA, databaseS, databaseB, pathToA, pathToB
modDateA=$(cat $1 | awk -v var=$nameline '{if (NR==var) print}' | awk '{print $7}' | sed "s/-//g")
modDateB=$(cat $3 | awk -v var=$nameline '{if (NR==var) print}' | awk '{print $7}' | sed "s/-//g")
echo modDateA: $modDateA
echo modDateB: $modDateB
if (( $(echo "$modDateA > $modDateB" | bc -l) )); then
mv "$pathToA""$name" "$pathToA""$name""_conflict"
#Rename the file with the most recent mod date to file_conflict in the metadata
conflictLine="${1/"$name"/"$name"_conflict}"
#Update the DB with both metadata, the file_conflict and the file.
echo "$conflictLine" >> $pathToDataBaseRAM
awk '{if (NR=='$nameline') print $0}' $3 >> $pathToDataBaseRAM
elif (( $(echo "$modDateA > $modDateB" | bc -l) )); then
#Rename the file with the most recent mod date in its arb
mv "$pathToB""$name" "$pathToB""$name"_conflict
#Rename the file with the most recent mod date to file_conflict in the metadata
conflictLine="${3/"$name"/"$name"_conflict}"
#Update the DB with both metadata, the file_conflict and the file.
echo "$conflictLine" >> $pathToDataBaseS
awk '{if (NR=='$nameline') print $0}' $1 >> $pathToDataBaseRAM
else
modTimeA=$(cat $1 | awk -v var=$nameline '{if (NR==var) print}' | awk '{print $8}' | sed "s/://g")
echo modA: $modTimeA
#Find the string at the line $nameline inside B
modTimeB=$(cat $3 | awk -v var=$nameline '{if (NR==var) print}' | awk '{print $8}' | sed "s/://g")
echo modB: $modTimeB
if (( $(echo "$modA > $modB" | bc -l) )); then
#Rename the file with the most recent mod date in its arb
mv "$pathToA""$name" "$pathToA""$name""_conflict"
#Rename the file with the most recent mod date to file_conflict in the metadata
conflictLine="${1/"$name"/"$name"_conflict}"
#Update the DB with both metadata, the file_conflict and the file.
echo "$conflictLine" >> $pathToDataBaseRAM
awk '{if (NR=='$nameline') print $0}' $3 >> $pathToDataBaseRAM
else
#Rename the file with the most recent mod date in its arb
mv "$pathToB""$name" "$pathToB""$name"_conflict
#Rename the file with the most recent mod date to file_conflict in the metadata
conflictLine="${3/"$name"/"$name"_conflict}"
#Update the DB with both metadata, the file_conflict and the file.
echo "$conflictLine" >> $pathToDataBaseS
awk '{if (NR=='$nameline') print $0}' $1 >> $pathToDataBaseRAM
fi
fi
}