473,771 Members | 2,365 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Re: Elisp Lesson on file processing (make downloadable copy of awebsite)

In this week i wrote a emacs program and tutorial that does archiving
a website for offline reading.
(See http://xahlee.org/emacs/make_download_copy.html )

In the process, i ran into a problem with the unix “cp” utility. I've
been a unix admin for Solaris during 1998-2004. Even the first time i
learned about cp, i noticed some pecularity. But only today, i thought
about it and wrote it out exactly what's going on.

Here's a excerpt from my emacs tutorial above regarding the issue.
------------------

Copying a bunch of directories seems a trivial operation, but it
actually took me a couple hours to arrive at the final code, due to
the exact requirement of directory paths, and the unix “cp”tool's
lack of precision and flexibility.

Originally, i thought the code would be something simple like several
“(shell-command (concat "cp -R " fromDir " " toDir))”, one for each
source dir, where fromDir and toDir are full paths. However, it turns
out the problem is slightly more complex.

Suppose the source dir is “/Users/xah/web/emacs” and dest dir is “/
Users/xah/web/diklo/xahtut/emacs” and i want all branches under the
source dir copied into the dest dir.

If you do “cp -R /Users/xah/web/emacs /Users/xah/web/diklo/xahtut/
emacs” with both xahtut and xahtut/emacs doesn't exist, then this
error results: “cp: /Users/xah/web/diklo/xahtut/emacs: No such fileor
directory”.

If you do “cp -R /Users/xah/web/emacs /Users/xah/web/diklo/xahtut/
emacs” with xahtut/emacs exists, then you got “/Users/xah/web/diklo/
xahtut/emacs/emacs”, which is not what i want.

If you do “cp -R /Users/xah/web/emacs /Users/xah/web/diklo/xahtut”
with xahtut doesn't exist, it results in all branches of emacs in
xahtut, which is wrong.

Only when you do “cp -R /Users/xah/web/emacs /Users/xah/web/diklo/
xahtut” with xahtut exists, you get the correct result with the new
dir “/Users/xah/web/diklo/xahtut/emacs” having all branchesof the
original dir.

So, the solution is to first create all the parent dirs of the dest
dir, but without the dest dir node itself. Then, do a cp to the first
parent of dest dir.

Directories are abstractly a tree. Copying directories is like
grafting a tree from one branch into another branch. To begin, we are
given two spec: the source node and a destination node. The source
node by definition is a existing node (i.e. existing dir or file),
otherwise the copying won't make sense. However, the destination spec
can be a node that doesn't exist, or its parents doesn't exist, or
several levels of parents doesn't exist. When the destination spec has
missing nodes, we can consider creating them as part of the grafting
process, or we can consider it as a error.

The unix “cp” tool's behavior is mathematically inconsistent. When the
destination node exist, the source node will become new children of
destination node. When the destination node does not exist (but its
parent exists), “cp” will create the node, and copy only the children
of the source node to it. When the destination node doesn't exist and
its parent doesn't exist neither, then “cp” considers it a error.

---------------
Related readings:

• The Nature of the “Unix Philosophy”
http://xahlee.org/UnixResource_dir/writ/unix_phil.html

Xah
http://xahlee.org/


Jul 6 '08 #1
2 1402
On Jul 6, 4:05 am, "xah...@gmail.c om" <xah...@gmail.c omwrote:
In this week i wrote a emacs program and tutorial that does archiving
a website for offline reading.
(Seehttp://xahlee.org/emacs/make_download_c opy.html)
Why not use wget or curl?
Jul 10 '08 #2
Xah Lee wrote:
«
... emacs program and tutorial that does archiving a website for
offline reading. (See http://xahlee.org/emacs/make_download_copy.html
)
»

Sashi wrote:
«Why not use wget or curl?»

The Emacs lisp program makes a archive of parts of website you own, so
that readers of your website can click download to read it offline.

For wget and curl, i have some tips here:
http://xahlee.org/UnixResource_dir/unix_tips.html

Xah
http://xahlee.org/


Jul 11 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

49
4151
IDE
by: Thomas Lindgaard | last post by:
Hello I am probably going to start a war now... but so be it :) I just want to hear what all you guys who eat pythons for breakfast use for python coding. Currently I use Kate, but I would really like an IDE with debugger and a source browser (ie. one the I can use to browse through modules etc. when looking for just the right curses stuff and such - I am a newcomer to Python).
5
1113
by: matt dittman | last post by:
I have created a windows service that reads emails from a drop directory and moves them to the appropriate mail folder every 15 seconds. I can move, rename and delete the files as needed, up until the CDO.DropDirectory.GetMessages() method is called. At this point, the files are locked until I shut down the service. After processing and delivery, I need to be able to delete all the files in the drop directory. I can delete them via...
0
1782
by: Joe Mayo | last post by:
I've recently updated the C# Tutorial at C# Station with a new addition, Lesson 17: Enums. The C# Tutorial may be found at http://www.csharp-station.com/Tutorial.aspx. Other updates include: 1. Downloadable source code. 2. All example programs run on-line as NTD apps. 3. A support forum for discussing the Tutorial.
3
7666
by: ecov | last post by:
Is there any easy way to read into a dataset a file that was created from a BCP command. The file is in a fixed length format. I would also like to be able to write out a dataset to the same type of file structure. The obvious solution would be to use XML file processing however that is not an option as I have a third party vendor that is not capable of processing XML files.
3
2045
by: Juan R. | last post by:
In http://canonicalscience.blogspot.com/2006/04/scientific-language-canonml-is.html] I presented some generic requirements for a markup language for science and mathematics. Basic features of CanonML and ampliations and improvements over TeX, SGML, XML or Scheme based encodings are listed below. However, let me an incise first. Rememeber how we also saw that the mathematics in Distler's blog Musings were being incorrectly encoded with...
1
7292
by: xahlee | last post by:
Elisp Tutorial: Make Google Earth Xah Lee, 2006-12 This page shows a example of writing a emacs lisp function that creates a Google Earth file, and creates a link to the file, as well a link to Google Map. If you don't know elisp, first take a gander at Elisp Basics. I often write travelogs on my website. If i traveled to Las Vegas, then
6
24157
by: ivan.perak | last post by:
Hello, im a beginner in VB.NET... The thing i would like to do is as it follows.... I have a text file (list of names, every name to the next line) which is about 350000 lines long. I would like to split it and create a new file at every lets say 20000 lines... so, the directory output would have to be something like this:
1
64192
AdrianH
by: AdrianH | last post by:
Assumptions I am assuming that you know or are capable of looking up the functions I am to describe here and have some remedial understanding of C programming. FYI Although I have called this article How to Parse a File in C++, we are actually mostly lexing a file which is the breaking down of a stream in to its component parts, disregarding the syntax that stream contains. Parsing is actually including the syntax in order to make...
1
47485
KevinADC
by: KevinADC | last post by:
Note: You may skip to the end of the article if all you want is the perl code. Introduction Many websites have a form or a link you can use to download a file. You click a form button or click on a link and after a moment or two a file download dialog box pops-up in your web browser and prompts you for some instructions, such as open or save. Im going to show you how to do that using a perl script. What You Need Any recent...
0
9454
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10261
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10103
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10038
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9911
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5354
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5482
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4007
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3609
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.