@@ -118,22 +118,28 @@ function isfolderempty {
118
118
119
119
# files or non-empty folders without .meta files
120
120
function findorphanfiles {
121
- find ${1-.} -not -name ' *.meta' -and -not -path ' */\.*' -and -not -path ' .' |
121
+ local folder=" ${1-.} "
122
+ find " $folder " -not -name ' *.meta' -and -not -path ' */\.*' -and -not -path ' .' |
122
123
while read path
123
124
do
125
+ # skip topmost
126
+ if [[ " $folder " == " $path " ]]
127
+ then
128
+ continue
129
+ fi
124
130
# missing .meta file?
125
131
if [ ! -f " ${path} .meta" ]
126
132
then
127
133
# is file?
128
- if [ -f $path ]
134
+ if [ -f " $path " ]
129
135
then
130
136
echo $path
131
137
# is folder and not empty?
132
- elif [ -d $path ]
138
+ elif [ -d " $path " ]
133
139
then
134
- if ! isfolderempty $path
140
+ if ! isfolderempty " $path "
135
141
then
136
- echo $path
142
+ echo " $path "
137
143
fi
138
144
fi
139
145
fi
@@ -148,14 +154,14 @@ function findorphanmeta {
148
154
local other=" ${path/% .meta} "
149
155
150
156
# is empty folder?
151
- if [ -d $other ]
157
+ if [ -d " $other " ]
152
158
then
153
159
if isfolderempty $other
154
160
then
155
161
echo $path
156
162
fi
157
163
# missing file?
158
- elif [ ! -f $other ]
164
+ elif [ ! -f " $other " ]
159
165
then
160
166
echo $path
161
167
fi
@@ -164,9 +170,10 @@ function findorphanmeta {
164
170
165
171
function generatemeta {
166
172
local COUNTER=$(( 0 ))
173
+ local folder=" ${1-.} "
167
174
while read path
168
175
do
169
- if [ -d $path ]
176
+ if [ -d " $path " ]
170
177
then
171
178
# folder
172
179
metatemplate " " > " ${path} .meta"
@@ -178,7 +185,7 @@ function generatemeta {
178
185
(( COUNTER++ ))
179
186
echo " Generated for \" ${path##* .} \" file: ${path} .meta"
180
187
fi
181
- done < <( findorphanfiles ${1-.} )
188
+ done < <( findorphanfiles " $folder " )
182
189
echo " <<< Generated $COUNTER meta files."
183
190
}
184
191
@@ -187,14 +194,14 @@ function removeorphans {
187
194
while read path
188
195
do
189
196
local other=" ${path/% .meta} "
190
- if [ -d $other ]
197
+ if [ -d " $other " ]
191
198
then
192
199
# remove empty folder
193
- rm -rf $other
200
+ rm -rf " $other "
194
201
fi
195
202
196
203
# remove meta file
197
- rm $path
204
+ rm " $path "
198
205
(( COUNTER++ ))
199
206
echo " Removed orphaned \" .meta\" file: $path "
200
207
done < <( findorphanmeta ${1-.} )
0 commit comments