Simple C / Shell program that adds file tagging capability to Unix filesystem.
The purpose of this project was to build a program capable of adding semantic information to the Unix
file system through file tags. For example user will be able to tag files as important
, public
, private
, draft
, etc.
Application is in French and has been built on December 2007 under Linux Fedora Core 5. I tried to respect POSIX standards as much as possible so it should be compatible with other distributions as well.
It uses simple C programs and Shell scripts.
It was originally compiled with GCC for 32 bits systems. I recompiled it recently for 64 bits systems.
- Get the archive from this project (bin/file-tagger.tar.gz), then uncompress and extract it wherever you want (i.e. /usr/local)
tar zxvf file-tagger.tar.gz -C /usr/local
- From the application folder, execute the
configure.sh
file which will set permissions and create aliases (also in the /etc/profile file)You can also do it manually if you prefer, just inspect the file.cd /usr/local/file-tagger ./configure.sh
- Run available commands, see Execute
-
Make sure you have the right libraries (SQLite) to be able to compile the C files :
sudo apt-get install sqlite3 sudo apt-get install libsqlite3-dev
-
Get the sources from this project (src folder) then compile them :
gcc src/AfficherTags.c -lsqlite3 -o AfficherTags gcc src/AjouterTag.c -lsqlite3 -o AjouterTag gcc src/AjouterTagIncompatibles.c -lsqlite3 -o AjouterTagIncompatibles gcc src/SupprimerTag.c -lsqlite3 -o SupprimerTag gcc src/SupprimerTagIncompatibles.c -lsqlite3 -o SupprimerTagIncompatibles gcc src/ViderTableTags.c -lsqlite3 -o ViderTableTags
Simply use the available commands (once aliases have been created) :
addtag file/directory tag
→ add a tag on one or multiple filesdeltag file/directory tag
→ remove a tag from one or multiple filesaddincompatibletags tag1 tag2
→ set 2 tags as incompatibledelincompatibletags tag1 tag2
→ remove the incompatibility between 2 tagsshowtags
→ show all tags in all tagged filesdelalltags
→ remove all tags from all tagged filesls --tag [option] tag
→ list files tagged with the specified tagrm --tag tag
→ remove files tagged with the specified tag
See the Examples section.
- Remove the aliases by running the
uninstall.sh
scriptcd /usr/local/file-tagger ./uninstall.sh
- Remove the application folder
rm -rf /usr/local/file-tagger
So we have 6 C files that allow us to interact with the SQLite database. These are the following files :
SupprimerTag.c
AjouterTag.c
AfficherTags.c
ViderTableTags.c
SupprimerTagIncompatibles.c
AjouterTagIncompatibles.c
And 2 Shell scripts that allow us to override the ls
and rm
commands when the --tag
option is specified (it runs native ls
and rm
commands when the option is not
specified). These are the files :
SupprimerFichier.sh
AfficherFichier.sh
The configuration.h
file contains the SQL queries (definitions) and the path to the database file (by default in the current directory where the program will be placed).
It is only used for compilation.
The configure.sh
file is a helper file used to set permissions and create aliases (also in the /etc/profile file).
The uninstall.sh
file is a helper file used to remove alias
None of the functions modify the Unix file system itself, you only need to delete the file representing the database (tag_base.db
) so that everything becomes normal again (no
more tagged files, incompatible tags, etc ...).
Only the execution of rm --tag tag
will permanently delete the tagged file and is therefore irreversible.
It is done by executing the addtag
command which will :
- check if the file or folder passed in parameter exists
- create the database if it does not exist
- if the argument passed as first parameter is a file :
- check if the file is already tagged
- if it already is, checks that there is no incompatibility of tags
- get the inode of the file and store it with the filename and its tag in the
tags
table into the database
- if the argument passed in 2nd parameter is a directory, we go through it recursively, and for each element, we call the function to tag the files (step 3 above is executed for each of the files)
When tagging a directory, you can interrupt the process using ctrl + c
;
It is done by executing the deltag
command which will :
- check if the file or folder passed in parameter exists
- if the argument passed in 1st parameter is a file :
- check if the file is tagged
- if it is, deleted it from the
tags
table from the database
- if the argument passed as second parameter is a directory, we go through it recursively, and for each element, we call the function to "untag" all the files (step 3 above is executed for each files)
It is done by executing the addincompatibletag
command which will :
- check that the tags are not already incompatible
- add the two incompatible tags in the
incompatible_tags
table into the database (add a record)
It is done by executing the delincompatibletag
command which will :
- check that the tags are not already incompatible
- delete the two incompatible tags from the
incompatible_tags
table from the database (remove the record)
It is done by executing the delincompatibletag
command which will simply retrieve the content of the tags
table from the database (user-friendly formatted).
It is done by executing the showincompatibletags
command which will simply retrieve the content of the incompatible_tags
table from the database (user-friendly formatted).
It is done by executing the delalltags
command which will simply remove the content of the tags
table from the database (delete all records).
It is done by executing the ls –tag [option] tag
command which will :
- select corresponding files (paths) from
tags
table from the database - do a
ls
for each of the paths so they are displayed - if the
--tag
option is not specified, we just run the nativels
command with the specified parameters
It uses the AfficherFichier.sh
script.
It is done by executing the rm –tag [option] tag
command which will :
- select corresponding files (paths) from
tags
table from the database - do a
rm
for each of the paths so they are displayed - if the
--tag
option is not specified, we just run the nativerm
command with the specified parameters
It uses the SupprimerFichier.sh
script.
The SQLite database is very light, and contains only 2 tables :
tags
(id
,inodeFile
,fileName
,tagName
);incompatible_tags
(id
,tagName
,tagName2
);
The tag
table therefore contains all the files with their associated tag, and the incompatibles_tags
table contains all incompatible tag pairs.
General Public License (GPL) v3
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 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.
You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.