Skip to content

locateJson: a tool for converting mlocate databases to JSON.

License

Notifications You must be signed in to change notification settings

jamesmistry/locatejson

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

49 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

locateJson

Build Status

Overview

locateJson: a tool for converting mlocate databases to JSON.

mlocate databases contain an index of files and directories for efficient lookup. man locate and man mlocate.db for more details.

TL; DR

From the repository root:

cmake -DCMAKE_BUILD_TYPE=Release ./
make
make install
ln -s /opt/locatejson/bin/locatejson /usr/bin/locatejson

Then (you may need to sudo):

locatejson -o /tmp/output.json

Pretty-printed JSON

locateJson can't produce pretty-printed JSON itself, but you can use Python to do this:

python -m json.tool ugly.json > pretty.json

Handling Massive Databases

The maximum file sizes supported by locateJson are limited only by your file system.

locateJson intentionally doesn't use much memory - the mlocate database and resulting JSON aren't buffered, so locateJson's memory usage is low regardless of how big they are.

Building & Testing

What you need

  • C++11 compatible compiler (at least g++ 4.8.5 recommended)
  • cmake >= version 2.6
  • gtest development package (unit testing framework)
  • valgrind, for dynamic analysis tests
  • cppcheck, for static analysis tests

Instructions

From the repository root:

cmake -DCMAKE_BUILD_TYPE=Release ./
make
make test

Packaging & Installing

What you need

If you're using a DEB or RPM based platform, it's recommended you generate a compatible package (see below for instructions) and install using this. To do this, you'll need package building tools such as:

  • rpm-build
  • builddeb

Instructions

To install from a package:

In the repository root, run one of the following commands depending on whether you want to generate an RPM or DEB package:

cmake -DCMAKE_BUILD_TYPE=Release -DCPACK_GENERATOR=RPM ./

or

cmake -DCMAKE_BUILD_TYPE=Release -DCPACK_GENERATOR=DEB ./

Run the following commands:

make
make package

Install the package now present in the repository root, e.g.

sudo yum install locatejson-0.1-1.x86_64.rpm 

or

sudo dpkg -i locatejson-0.1-1.x86_64.deb

To install without generating a package:

cmake -DCMAKE_BUILD_TYPE=Release ./
make
make install

Usage

Synopsis

locatejson [-n ] [-o ] [-i ] [--] [--version] [-h]

Options

  • -n , --hostname Hostname to associate with the file entries in the converted JSON. If ommitted, the current host's name is used.
  • -o , --output Filename of the JSON file to write. If ommitted, standard output is used.
  • -i , --input Filename of the database to convert. If ommitted, /var/lib/mlocate/mlocate.db is used.
  • --, --ignore_rest Ignores the rest of the labeled arguments following this flag.
  • --version Displays version information and exits.
  • -h, --help Displays usage information and exits.

Exit status

The exit status is 0 if the database was successfully converted, and 1 if an error occurred.

About

locateJson: a tool for converting mlocate databases to JSON.

Resources

License

Stars

Watchers

Forks

Packages

No packages published