The other day, Yandex opened
the Yandex.Disk API documentation , and I want to tell you about the example program created on the basis of this API.
Yandex.Disk has separate client programs for Windows and Mac OS X that support a local copy of the file storage. It is incredibly comfortable! We must pay tribute to Dropbox, who, it seems, was the first to propose exactly this way of using cloud file storage.
There is no client for Linux, but Yandex.Disk supports access to files using the open and well-proven
WebDAV protocol for many years. WebDAV support in the Linux kernel allowed us to create a prototype of the Yandex.Disk sync client with relatively little blood.
')
The current version is available on the githaba - this is about 130 lines of Perl code, and here I will briefly describe how it works and works.
Short disclaimer: as long as it is mostly a prototype, it is not recommended to use the program to synchronize important data. The client has so far only rudimentary error handling, and also spends much more memory, processor and traffic than can be.The YandexDisk subdirectory appears in the user's home directory, which contains the local copy of files from the Disk, as well as the hidden directory .yadisk-davfs, which is the mount point for the davfs2 file system and provides file access to real data in the Yandex cloud. The task of the synchronizer is to maintain these two directories in an identical form, picking up changes in each of them.
This task yadisk-sync solves with the help of three important tools:
- First, the inotify mechanism, available in all modern kernels, is used to monitor changes in the local copy.
- Secondly, to receive changes from the cloud, a subscription to XMPP messages is used. This part of the Yandex.Disk protocol has not yet been documented.
- Thirdly, the well-known unison package is used to synchronize two directories. It is he who does the lion’s share of the synchronization work.
Any changes, local or remote, lead to the launch of unison, which, using the rsync-like protocol, as well as knowledge about the state of directories stored during previous launches, copies, deletes and edits files so that both directories contain the same thing.
The yadisk-sync.pl program itself is not demonized for easier debugging, and for installation and configuration it requires following the instructions from the README.txt file. All this was tested only on Ubuntu 11.10 and Mint 12.
Try it, maybe someone will inspire this prototype to some interesting developments. Or use the Disk API to create completely new programs and applications.